diff --git a/.gitignore b/.gitignore index 26e82f6..4f66732 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ .env .air -build \ No newline at end of file +build + +.vscode +.idea \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index ef386dd..a53ebcc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,29 @@ # Build stage FROM cgr.dev/chainguard/go:latest AS builder + WORKDIR /app + COPY go.mod go.sum ./ RUN go mod download + COPY . . RUN CGO_ENABLED=0 go build -o memogram ./bin/memogram RUN chmod +x memogram # Run stage FROM cgr.dev/chainguard/static:latest-glibc + +# Create a non-root user and group +# Chainguard images often run as uid 65532 (nonroot) +USER 65532:65532 + WORKDIR /app + ENV SERVER_ADDR=dns:localhost:5230 ENV BOT_TOKEN=your_telegram_bot_token -COPY .env.example .env -COPY --from=builder /app/memogram . + +# Copy files with proper ownership +COPY --from=builder --chown=65532:65532 /app /app +COPY --chown=65532:65532 .env.example .env + CMD ["./memogram"] diff --git a/README.md b/README.md index dbf3e5f..b8c92ae 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ ALLOWED_USERNAMES=user1,user2,user3 - `BOT_TOKEN`: Your Telegram bot token - `BOT_PROXY_ADDR`: Optional proxy address for Telegram API (leave empty if not needed) - `ALLOWED_USERNAMES`: Optional comma-separated list of allowed usernames (without @ symbol) +- `DATA`: Path to the file storing the user's authentication token ### Username Restrictions @@ -89,25 +90,18 @@ Or you can start the service with Docker: #### Starting with Docker Compose -Or you can start the service with Docker Compose. This can be combined with the `memos` itself in the same compose file: +You can also use Docker Compose to manage the service. There is a sample `docker-compose.yaml` file in this repository +that includes memos and memogram as a quickstart setup. 1. Create a folder where the service will be located. 2. Clone this repository in a subfolder `git clone https://github.com/usememos/telegram-integration memogram` 3. Create `.env` file ```sh - SERVER_ADDR=dns:yourMemosUrl.com:5230 + SERVER_ADDR=dns:memos:5230 BOT_TOKEN=your_telegram_bot_token ``` -4. Create Docker Compose `docker-compose.yml` file: - ```yaml - services: - memogram: - env_file: .env - build: memogram - container_name: memogram - ``` -5. Run the bot via `docker compose up -d` -6. The Memogram service should now be running inside the Docker container. You can interact with it via your Telegram bot. +4. Run the bot via `docker compose up -d` +5. The Memogram service should now be running inside the Docker container. You can interact with it via your Telegram bot. ### Interaction Commands diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..da51d8e --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,21 @@ +services: + memos: + image: neosmemo/memos:stable + container_name: memos + ports: + - 5230:5230 + networks: + - memos-network + + memogram: + build: . + env_file: .env + container_name: memogram + depends_on: + - memos + networks: + - memos-network + +networks: + memos-network: + name: memos-network