From a742e481ab0124605231e9f30cb8f4222eb131dc Mon Sep 17 00:00:00 2001 From: noxzym Date: Sat, 23 Mar 2024 20:44:02 +0700 Subject: [PATCH] feat(docker): dockerize project --- .github/workflows/build-docker.yml | 18 ++++++++++++ Dockerfile | 45 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 .github/workflows/build-docker.yml create mode 100644 Dockerfile diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 00000000..d1f4b3a4 --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,18 @@ +name: Build & Push Docker Image to container image registry + +on: + release: + types: [created] + push: + branches: + - main + pull_request: + branches: + - main + paths: + - "Dockerfile" + +jobs: + docker: + uses: clytage/workflows/.github/workflows/docker-build.yml@main + secrets: inherit \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..d91e9eb0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,45 @@ +FROM ghcr.io/hazmi35/node:20-dev-alpine as build-stage + +# Prepare pnpm with corepack (experimental feature) +RUN corepack enable && corepack prepare pnpm@latest + +# Copy package.json, lockfile and npm config files +COPY package.json pnpm-lock.yaml *.npmrc ./ + +# Fetch dependencies to virtual store +RUN pnpm fetch + +# Install dependencies +RUN pnpm install --offline --frozen-lockfile + +# Copy Project files +COPY . . + +# Build TypeScript Project +RUN pnpm run build + +# Prune devDependencies +RUN pnpm prune --production + +# Get ready for production +FROM ghcr.io/hazmi35/node:20-alpine + +LABEL name "bajigur" +LABEL maintainer "Stegripe " + +# Install ffmpeg +RUN apk add --no-cache ffmpeg + +# Copy needed files +COPY --from=build-stage /tmp/build/package.json . +COPY --from=build-stage /tmp/build/node_modules ./node_modules +COPY --from=build-stage /tmp/build/dist ./dist + +# Additional Environment Variables +ENV NODE_ENV production + +# Add scripts volumes +VOLUME /app/auth_state + +# Start the app with node +CMD ["node", "dist/index.js"] \ No newline at end of file