Skip to content

Commit

Permalink
Add dockerfile & gh workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperzuk-neti committed Sep 11, 2024
1 parent b1b334b commit c08e161
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
dist/
prisma/generated/
prismaDmob/generated/
node_modules/
60 changes: 60 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build docker image
on:
pull_request:
types: [opened, synchronize]
push:
branches:
- develop
- docker

jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
postgresDmob:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432
env:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
DMOB_DATABASE_URL: postgres://postgres:postgres@localhost:5433/postgres
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Install prisma
run: npm install prisma@latest

- name: Init tmp db
run: npx prisma migrate reset --force --schema=./prisma/schema.prisma

- name: Init dmob-like tmp db
run: npx prisma migrate reset --force --schema=./prismaDmob/schema.prisma

- name: Build
env:
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres
DMOB_DATABASE_URL: postgres://postgres:[email protected]:5433/postgres
run: docker build --secret id=DATABASE_URL --secret id=DMOB_DATABASE_URL . --add-host=host.docker.internal:host-gateway

26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:20-alpine AS builder
USER node
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY --chown=1000:1000 . .
RUN --mount=type=secret,id=DATABASE_URL,uid=1000 \
env DATABASE_URL=$(cat /run/secrets/DATABASE_URL) \
npx prisma generate --sql --schema=./prisma/schema.prisma

RUN --mount=type=secret,id=DMOB_DATABASE_URL,uid=1000 \
env DMOB_DATABASE_URL=$(cat /run/secrets/DMOB_DATABASE_URL) \
npx prisma generate --sql --schema=./prismaDmob/schema.prisma

RUN npm run build

FROM node:20-alpine AS runner
ENV NODE_ENV=production
USER node
WORKDIR /app
COPY --from=builder --chown=node:node /app/package*.json ./
COPY --from=builder --chown=node:node /app/node_modules/ ./node_modules/
COPY --from=builder --chown=node:node /app/dist/ ./dist/
COPY --from=builder --chown=node:node /app/prisma/ ./prisma/
COPY --from=builder --chown=node:node /app/prismaDmob/ ./prismaDmob/
CMD [ "node", "dist/main.js" ]

0 comments on commit c08e161

Please sign in to comment.