From 2224b3ed70928996b0e4a1d0150ad46e9a0f1670 Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 30 Jan 2024 10:24:15 -0800 Subject: [PATCH 1/5] feat: adding dockerfile based on registration app --- client/Dockerfile | 48 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 client/Dockerfile diff --git a/client/Dockerfile b/client/Dockerfile new file mode 100644 index 00000000..b44fc2d7 --- /dev/null +++ b/client/Dockerfile @@ -0,0 +1,48 @@ +FROM debian:11 + +RUN apt-get update && \ + apt-get install -y git gnupg curl && \ + apt-get clean + +ENV USER_ID=1001 +ENV HOME=/root + +WORKDIR ${HOME} + +COPY ./ ${HOME}/ + +RUN git clone https://github.com/asdf-vm/asdf.git ${HOME}/asdf --depth 1 --branch v0.14.0 + +ENV BASH_ENV="${HOME}/asdf/asdf.sh" +# Because asdf is loaded via BASH_ENV, all commands using adsf need to be executed using /usr/bin/env bash -c +SHELL ["/usr/bin/env", "bash", "-c"] + +COPY .tool-versions ${HOME}/.tool-versions +# The client only needs yarn and node +RUN sed -i -nr '/node|yarn/p' ${HOME}/.tool-versions && \ + cat ${HOME}/.tool-versions | cut -f 1 -d ' ' | xargs -n 1 asdf plugin-add && \ + asdf plugin-update --all && \ + asdf install && \ + asdf reshim + +ADD https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 /usr/local/bin/dumb-init +RUN chmod +x /usr/local/bin/dumb-init +ENTRYPOINT ["dumb-init", "--"] + +ENV NODE_ENV=production + +RUN yarn install --frozen-lockfile --production=false && \ + yarn build && \ + yarn install --frozen-lockfile --production=true && \ + yarn cache clean && \ + # Make everything in the home group-writable to support OpenShift's restricted SCC + # Needs to be done as root to chown + # same layer as yarn install to keep re-chowned files from using up several hundred MBs more space + useradd -ms /bin/bash -d ${HOME} --uid ${USER_ID} -g root client && \ + chown -R client:0 ${HOME} && \ + chmod -R g+rwX ${HOME} + +EXPOSE 3000 9000 +USER ${USER_ID} + +CMD ["/usr/bin/env", "bash", "-c", "yarn start"] From c757910f7add468d0546758d6acb433dd0c16119 Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 30 Jan 2024 10:25:41 -0800 Subject: [PATCH 2/5] feat: gh build action --- .github/workflows/build-and-test.yaml | 52 +++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .github/workflows/build-and-test.yaml diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml new file mode 100644 index 00000000..b485565c --- /dev/null +++ b/.github/workflows/build-and-test.yaml @@ -0,0 +1,52 @@ +name: Build and Test Reporting App + +on: + push: + branches: [develop, main, feat/37-client-docker-file] + pull_request: + branches: [develop, main] + workflow_dispatch: + +jobs: + frontend-docker-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 + with: + install: true + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/bcgov/cas-reporting-frontend + tags: | + type=sha,format=long,prefix= + latest + type=ref,event=pr + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-client-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx-client + - name: Build image + uses: docker/build-push-action@v5 + with: + context: client + builder: ${{ steps.buildx.outputs.name }} + push: true + file: client/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha \ No newline at end of file From cdeb46e5fc70c03cb994fe192437468bfdd19ed7 Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 30 Jan 2024 10:32:52 -0800 Subject: [PATCH 3/5] chore: using github action cache as per docs --- .github/workflows/build-and-test.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index b485565c..af4ae523 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -2,7 +2,7 @@ name: Build and Test Reporting App on: push: - branches: [develop, main, feat/37-client-docker-file] + branches: [develop, main] pull_request: branches: [develop, main] workflow_dispatch: @@ -32,13 +32,6 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Cache Docker layers - uses: actions/cache@v4 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-client-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx-client - name: Build image uses: docker/build-push-action@v5 with: @@ -49,4 +42,5 @@ jobs: tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha - cache-to: type=gha \ No newline at end of file + cache-to: type=gha + \ No newline at end of file From 990a652a775d2dddb67a2bf5d7f2be8bd71e75d1 Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 30 Jan 2024 11:16:39 -0800 Subject: [PATCH 4/5] chore: end of file --- .github/workflows/build-and-test.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index af4ae523..3b0b4ecf 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -43,4 +43,3 @@ jobs: labels: ${{ steps.meta.outputs.labels }} cache-from: type=gha cache-to: type=gha - \ No newline at end of file From 83032accb49483fe7b5f669edb1e6d2b9aaaa8fb Mon Sep 17 00:00:00 2001 From: Pierre Bastianelli Date: Tue, 30 Jan 2024 12:57:41 -0800 Subject: [PATCH 5/5] chore: removing yarn dev build --- client/Dockerfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/client/Dockerfile b/client/Dockerfile index b44fc2d7..15c300d0 100644 --- a/client/Dockerfile +++ b/client/Dockerfile @@ -31,9 +31,7 @@ ENTRYPOINT ["dumb-init", "--"] ENV NODE_ENV=production -RUN yarn install --frozen-lockfile --production=false && \ - yarn build && \ - yarn install --frozen-lockfile --production=true && \ +RUN yarn install --frozen-lockfile --production=true && \ yarn cache clean && \ # Make everything in the home group-writable to support OpenShift's restricted SCC # Needs to be done as root to chown