From 0a854695107dd32ebd3649541737adc612861eb5 Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 22:13:04 +0200 Subject: [PATCH 1/6] Update dockerfile for future builds --- Dockerfile | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed587db1f..ca782c441 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,2 @@ -FROM node:16.15.0-alpine3.15 as build - -WORKDIR /app - -COPY ./package.json /app/package.json -COPY ./yarn.lock /app/yarn.lock - -COPY . . -RUN yarn install -RUN yarn export - FROM nginx:1.21.6 -COPY --from=build /app/out /usr/share/nginx/html +COPY ./out /usr/share/nginx/html \ No newline at end of file From 273d11a65431c5bef04272ce06d656c557c7f56d Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 22:25:22 +0200 Subject: [PATCH 2/6] Try to add GitHub action --- .github/workflows/docker.yml | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/docker.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..ecff66cb9 --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,45 @@ +name: Demo Push + +on: + push: + tags: + - v* + +env: + IMAGE_NAME: mhp + +jobs: + # Push image to GitHub Packages. + # See also https://docs.docker.com/docker-hub/builds/ + push: + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v3 + + - name: Build image + run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + + - name: Log in to registry + # This is where you will update the PAT to GITHUB_TOKEN + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + + - name: Push image + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME + + # Change all uppercase to lowercase + IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') + # Strip git ref prefix from version + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') + # Strip "v" prefix from tag name + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') + # Use Docker `latest` tag convention + [ "$VERSION" == "master" ] && VERSION=latest + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION \ No newline at end of file From f0042f81e02f25fafac372290df5b5be4f1b8158 Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 23:07:37 +0200 Subject: [PATCH 3/6] Trying to implement multi stage build --- .github/workflows/docker.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index ecff66cb9..b60b10297 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -19,7 +19,11 @@ jobs: steps: - uses: actions/checkout@v3 - + - uses: actions/cache@v2 + id: restore-build + with: + path: ./out/ + key: ${{ github.sha }} - name: Build image run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" From 8f60442b49f0f5fa7632061f25dab69e84d081cb Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 23:21:02 +0200 Subject: [PATCH 4/6] Add multi stage docker build and release --- .github/workflows/docker.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index b60b10297..68ef43f83 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -11,8 +11,22 @@ env: jobs: # Push image to GitHub Packages. # See also https://docs.docker.com/docker-hub/builds/ + build: + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v3 + - uses: actions/checkout@v3 + - run: yarn install --frozen-lockfile + - run: yarn export + - uses: actions/cache@v2 + id: restore-build + with: + path: ./out/ + key: ${{ github.sha }} + push: runs-on: ubuntu-latest + needs: [build] permissions: packages: write contents: read @@ -25,12 +39,11 @@ jobs: path: ./out/ key: ${{ github.sha }} - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" + run: docker build . --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - name: Log in to registry - # This is where you will update the PAT to GITHUB_TOKEN - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin - name: Push image run: | IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME From c3d479996638da489b8e505261d044f65219f5ed Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 23:28:00 +0200 Subject: [PATCH 5/6] Add a latest push too --- .github/workflows/docker.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 68ef43f83..316c7988c 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -59,4 +59,5 @@ jobs: echo IMAGE_ID=$IMAGE_ID echo VERSION=$VERSION docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - docker push $IMAGE_ID:$VERSION \ No newline at end of file + docker push $IMAGE_ID:$VERSION + docker push $IMAGE_ID:latest \ No newline at end of file From ac81fcdb3c2b3a8c605e9d8ddeae4469a039fa89 Mon Sep 17 00:00:00 2001 From: Aj - Thomas Date: Mon, 9 May 2022 23:33:27 +0200 Subject: [PATCH 6/6] Add a latest push --- .github/workflows/docker.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 316c7988c..d862b38e4 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -60,4 +60,5 @@ jobs: echo VERSION=$VERSION docker tag $IMAGE_NAME $IMAGE_ID:$VERSION docker push $IMAGE_ID:$VERSION + docker tag $IMAGE_NAME $IMAGE_ID:latest docker push $IMAGE_ID:latest \ No newline at end of file