Skip to content

ci(github): publish docker image #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
"start:dev": "nest start --watch",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
Expand Down
Empty file added front/public/.gitkeep
Empty file.