Skip to content

Commit

Permalink
ci(github): publish docker image (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Jan 5, 2024
1 parent cc00218 commit e218d2b
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 28 deletions.
16 changes: 16 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#
*

#
!**/package.json
!/back/nest-cli.json
!/back/src
!/back/tsconfig.build.json
!/back/tsconfig.json
!/front/index.html
!/front/public/.gitkeep
!/front/src
!/front/tsconfig.json
!/front/tsconfig.node.json
!/front/vite.config.ts
!/package-lock.json
54 changes: 54 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#

name: Publish

on:
push:
branches:
- main
- alpha

workflow_dispatch:

permissions:
packages: write

jobs:
build:
name: Publich Docker Image
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/betagouv/espace-partenaire
tags: |
type=sha,format=long,prefix=
type=ref,event=branch
type=ref,event=tag
flavor: |
latest=${{ github.ref == 'refs/heads/main' }}
- uses: actions/checkout@v4
- name: Build image
uses: docker/build-push-action@v3
with:
build-args: |
SOURCE_COMMIT=${{ github.sha }}
cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache
cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64
push: true
tags: ${{ steps.meta.outputs.tags }}
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#

FROM node:lts-buster-slim as base

ENV TZ Europe/Paris
RUN cp /usr/share/zoneinfo/Europe/Paris /etc/localtime

RUN --mount=type=cache,target=/root/.npm,sharing=locked \
npm install -g npm@latest

WORKDIR /home/node/app

COPY ./package.json ./
COPY ./back/package.json ./back/
COPY ./front/package.json ./front/
COPY ./front/public/ ./front/public/

RUN --mount=type=cache,target=/root/.npm,sharing=locked \
npm install --omit=dev

#

FROM base AS build

RUN --mount=type=cache,target=/root/.npm,sharing=locked \
npm install

COPY ./back/ ./back/
COPY ./front/ ./front/

ENV NODE_ENV=production

RUN npm run build

#

FROM base

COPY --from=build /home/node/app/back/dist/ ./back/dist/
COPY --from=build /home/node/app/front/dist/ ./front/dist/

#

USER node
EXPOSE 3000/tcp
ENTRYPOINT [ "npm", "start" ]
21 changes: 0 additions & 21 deletions back/Dockerfile

This file was deleted.

6 changes: 0 additions & 6 deletions back/entrypoint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scalingo-prebuild": "cd ../front && npm install && npm run build && rm -rf ../back/front && cp -r dist ../back/front",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"start": "node dist/main.js",
"prestart:dev": "rm -rf dist",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
Expand Down
Empty file added front/public/.gitkeep
Empty file.

0 comments on commit e218d2b

Please sign in to comment.