From e65b207b5a1a09b2f9a65cf9b022176ff65335c1 Mon Sep 17 00:00:00 2001 From: Freekers <1370857+Freekers@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:52:37 +0200 Subject: [PATCH 1/8] Create Dockerfile --- Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9e5249f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,44 @@ +# Base image with Node and Python (since pnpm and Python are both needed) +FROM node:18-bullseye as builder + +# Set working directory in the container +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + libffi-dev \ + libnacl-dev \ + libssl-dev \ + python3 \ + python3-pip \ + git \ + && rm -rf /var/lib/apt/lists/* + +# Clone the project from GitHub +RUN git clone https://github.com/tapnisu/forwarding-discord-telegram.git /app + +# Install pnpm globally +RUN npm install -g pnpm + +# Install dependencies with pnpm +RUN pnpm install + +# Build the bot using pnpm +RUN pnpm build + +# Final stage for runtime +FROM node:18-bullseye-slim + +# Set working directory in the container +WORKDIR /app + +# Copy only the necessary built files from the builder stage +COPY --from=builder /app/node_modules /app/node_modules +COPY --from=builder /app/dist /app/dist +COPY --from=builder /app/package.json /app/package.json + +# Install pnpm globally +RUN npm install -g pnpm + +# Run the bot via pnpm +CMD ["pnpm", "start"] From ea7f775e97e4fe4a0fcf56ca9662c642cf4e622b Mon Sep 17 00:00:00 2001 From: Freekers <1370857+Freekers@users.noreply.github.com> Date: Wed, 23 Oct 2024 22:53:44 +0200 Subject: [PATCH 2/8] Create docker-compose.yml --- docker-compose.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..d6b6549 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +services: + forwarding-discord-telegram: + build: . + environment: + - DISCORD_TOKEN= + - TELEGRAM_TOKEN= + - TELEGRAM_CHAT_ID= + volumes: + - ./config.json:/app/config.json + restart: unless-stopped From 40b8755463af8a780a4f00a7e1572a8e825d0f23 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:20:49 +0700 Subject: [PATCH 3/8] Include dockerignore --- .dockerignore | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..cb80ae7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,121 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env.production + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +# Config file +config.json From 1d7758e0c9361abbc38af90f49c650d001c72913 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:33:04 +0700 Subject: [PATCH 4/8] Move prettier to prod deps --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 4fcc6b7..ddd46d9 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,8 @@ "@grammyjs/auto-retry": "^2.0.2", "discord.js-selfbot-v13": "^3.4.0", "dotenv": "^16.4.5", - "grammy": "^1.30.0" + "grammy": "^1.30.0", + "prettier": "^3.3.3" }, "devDependencies": { "@eslint/compat": "^1.2.0", @@ -40,7 +41,6 @@ "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.2.1", "globals": "^15.11.0", - "prettier": "^3.3.3", "typescript": "^5.6.3", "typescript-eslint": "^8.8.1" }, From 14bc49ea2a2d3f33a935b8cae13aa54edbfe51d2 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:33:10 +0700 Subject: [PATCH 5/8] Update lockfile --- pnpm-lock.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 43e34cd..6a44d4c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -20,6 +20,9 @@ importers: grammy: specifier: ^1.30.0 version: 1.30.0 + prettier: + specifier: ^3.3.3 + version: 3.3.3 devDependencies: '@eslint/compat': specifier: ^1.2.0 @@ -42,9 +45,6 @@ importers: globals: specifier: ^15.11.0 version: 15.11.0 - prettier: - specifier: ^3.3.3 - version: 3.3.3 typescript: specifier: ^5.6.3 version: 5.6.3 From 5be6c5a4e6eb34e674887830184c8e20791f85a3 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:34:22 +0700 Subject: [PATCH 6/8] Use alpine for docker (also split dev and prod deps) --- Dockerfile | 53 +++++++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9e5249f..7a53409 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,44 +1,25 @@ -# Base image with Node and Python (since pnpm and Python are both needed) -FROM node:18-bullseye as builder +FROM node:18-alpine3.20 AS base +LABEL authors="tapnisu" -# Set working directory in the container -WORKDIR /app - -# Install system dependencies -RUN apt-get update && apt-get install -y \ - libffi-dev \ - libnacl-dev \ - libssl-dev \ - python3 \ - python3-pip \ - git \ - && rm -rf /var/lib/apt/lists/* - -# Clone the project from GitHub -RUN git clone https://github.com/tapnisu/forwarding-discord-telegram.git /app +ENV PNPM_HOME="/pnpm" +ENV PATH="$PNPM_HOME:$PATH" -# Install pnpm globally -RUN npm install -g pnpm - -# Install dependencies with pnpm -RUN pnpm install +WORKDIR /app -# Build the bot using pnpm -RUN pnpm build +COPY package.json pnpm-lock.yaml /app/ +RUN corepack enable && corepack prepare -# Final stage for runtime -FROM node:18-bullseye-slim +FROM base AS prod-deps +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile -# Set working directory in the container -WORKDIR /app +FROM base AS build +RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile -# Copy only the necessary built files from the builder stage -COPY --from=builder /app/node_modules /app/node_modules -COPY --from=builder /app/dist /app/dist -COPY --from=builder /app/package.json /app/package.json +COPY . /app +RUN pnpm run build -# Install pnpm globally -RUN npm install -g pnpm +FROM base +COPY --from=build /app/dist /app/dist +COPY --from=prod-deps /app/node_modules /app/node_modules -# Run the bot via pnpm -CMD ["pnpm", "start"] +CMD [ "pnpm", "run", "start" ] From 2d69adde43ceaa22889764bcb280021f414db733 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:34:42 +0700 Subject: [PATCH 7/8] Prepare docker-compose for docker hub releases --- docker-compose.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index d6b6549..d0c45dd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,10 +1,11 @@ +name: forwarding-discord-telegram services: - forwarding-discord-telegram: - build: . + bot: + image: tapnisu/forwarding-discord-telegram:main environment: - - DISCORD_TOKEN= - - TELEGRAM_TOKEN= - - TELEGRAM_CHAT_ID= + DISCORD_TOKEN: ${DISCORD_TOKEN} + TELEGRAM_TOKEN: ${TELEGRAM_TOKEN} + TELEGRAM_CHAT_ID: ${TELEGRAM_CHAT_ID} volumes: - ./config.json:/app/config.json restart: unless-stopped From 440c5be2e59ac28826aec4938f5cbbb57e266320 Mon Sep 17 00:00:00 2001 From: Aleksei Rybin Date: Thu, 24 Oct 2024 15:35:45 +0700 Subject: [PATCH 8/8] Copy release workflow from tapris --- .github/workflows/release.yml | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4d5e0e2 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,51 @@ +name: Release + +on: + push: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + # list of Docker images to use as base name for tags + images: | + tapnisu/forwarding-discord-telegram + ghcr.io/tapnisu/forwarding-discord-telegram + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=sha + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }}