Skip to content

Commit

Permalink
Add Dockerfile (safe-global#2)
Browse files Browse the repository at this point in the history
* Add docker build to Github actions task
* Add support for releases
  • Loading branch information
Uxio0 authored May 31, 2023
1 parent cf250b9 commit 435914a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dockerfile
.dockerignore
node_modules
dist
47 changes: 44 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: CI

on:
push:
branches:
- main
pull_request:
release:
types: [ released ]

jobs:
prettier:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -16,7 +19,7 @@ jobs:
- run: npm i
- run: npm run format

es-lint:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -83,3 +86,41 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true

docker-publish:
if: github.ref == 'refs/heads/main' || (github.event_name == 'release' && github.event.action == 'released')
needs:
- format
- lint
- tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2.1.0
with:
platforms: arm64
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Deploy main
if: github.ref == 'refs/heads/master'
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: true
tags: safeglobal/safe-events-service:staging
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy Tag
if: (github.event_name == 'release' && github.event.action == 'released')
uses: docker/build-push-action@v4
with:
platforms: linux/amd64,linux/arm64
push: true
tags: |
safeglobal/safe-events-service:${{ github.event.release.tag_name }}
safeglobal/safe-events-service:latest
cache-from: type=gha
cache-to: type=gha,mode=max
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# BUILD CONTAINER
#
FROM node:18 as base
USER node
WORKDIR /app
COPY --chown=node:node package*.json tsconfig*.json ./
RUN npm install
COPY --chown=node:node . .
ENV NODE_ENV production
RUN npm run build

#
# PRODUCTION CONTAINER
#
ENV NODE_ENV production
FROM node:18 as production
USER node
COPY --chown=node:node --from=base /app/node_modules ./node_modules
COPY --chown=node:node --from=base /app/dist ./dist
CMD [ "node", "dist/main.js" ]

0 comments on commit 435914a

Please sign in to comment.