From c834e5bacebadf8487ad9c368a0357ef05c5232a Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Sun, 17 Oct 2021 12:22:52 +0100 Subject: [PATCH] Try upload html files --- .github/workflows/prod-deploy.yml | 162 +++++++++++++++++------------- 1 file changed, 94 insertions(+), 68 deletions(-) diff --git a/.github/workflows/prod-deploy.yml b/.github/workflows/prod-deploy.yml index 25ab526d..0d0eef07 100644 --- a/.github/workflows/prod-deploy.yml +++ b/.github/workflows/prod-deploy.yml @@ -8,6 +8,9 @@ on: push: branches: - master + + pull_request: + branches: [master] # release: # types: [published] @@ -18,19 +21,27 @@ jobs: steps: - uses: actions/checkout@v2.3.4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 + - name: Set up Node.js + uses: actions/setup-node@v2.4.1 + with: + node-version: 16 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 + - name: Install NPM Packages + run: npm ci - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-amd64-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx-amd64- + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v1 + + # - name: Set up Docker Buildx + # uses: docker/setup-buildx-action@v1 + + # - name: Cache Docker layers + # uses: actions/cache@v2 + # with: + # path: /tmp/.buildx-cache + # key: ${{ runner.os }}-buildx-amd64-${{ github.sha }} + # restore-keys: | + # ${{ runner.os }}-buildx-amd64- - name: Cache .next uses: actions/cache@v2 @@ -38,59 +49,64 @@ jobs: path: ${{ github.workspace }}/.next/cache key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json') }} - - name: Login to Docker Registry - uses: docker/login-action@v1 - with: - registry: registry.docker-box.richardwillis.info - username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} - password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.CR_PAT }} - - - name: Update version cache - run: | - date > VERSION - - - name: Build and push docker image - uses: docker/build-push-action@v2 - with: - context: ./ - file: ./Dockerfile - push: true - platforms: linux/amd64 - tags: registry.docker-box.richardwillis.info/${{ github.repository }}:latest - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - build-args: | - STRAPI_ENDPOINT=${{ secrets.STRAPI_ENDPOINT }} + # - name: Login to Docker Registry + # uses: docker/login-action@v1 + # with: + # registry: registry.docker-box.richardwillis.info + # username: ${{ secrets.DOCKER_REGISTRY_USERNAME }} + # password: ${{ secrets.DOCKER_REGISTRY_PASSWORD }} + + # - name: Login to GitHub Container Registry + # uses: docker/login-action@v1 + # with: + # registry: ghcr.io + # username: ${{ github.repository_owner }} + # password: ${{ secrets.CR_PAT }} + + # - name: Update version cache + # run: | + # date > VERSION + + # - name: Build and push docker image + # uses: docker/build-push-action@v2 + # with: + # context: ./ + # file: ./Dockerfile + # push: true + # platforms: linux/amd64 + # tags: registry.docker-box.richardwillis.info/${{ github.repository }}:latest + # cache-from: type=local,src=/tmp/.buildx-cache + # cache-to: type=local,dest=/tmp/.buildx-cache-new + # build-args: | + # STRAPI_ENDPOINT=${{ secrets.STRAPI_ENDPOINT }} # Temp fix # https://github.com/docker/build-push-action/issues/252 # https://github.com/moby/buildkit/issues/1896 - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache - - - name: Extract .next cache - run: | - docker pull registry.docker-box.richardwillis.info/${{ github.repository }}:latest - docker run -d --name helper registry.docker-box.richardwillis.info/${{ github.repository }}:latest tail -f /dev/null - docker cp helper:/app/.next . - docker stop helper - docker rm helper - - - name: Extract public assets - run: | - docker run -d --name helper registry.docker-box.richardwillis.info/${{ github.repository }}:latest tail -f /dev/null - docker cp helper:/app/public . - docker stop helper - docker rm helper + # - name: Move cache + # run: | + # rm -rf /tmp/.buildx-cache + # mv /tmp/.buildx-cache-new /tmp/.buildx-cache + + # - name: Extract .next cache + # run: | + # docker pull registry.docker-box.richardwillis.info/${{ github.repository }}:latest + # docker run -d --name helper registry.docker-box.richardwillis.info/${{ github.repository }}:latest tail -f /dev/null + # docker cp helper:/app/.next . + # docker stop helper + # docker rm helper + + # - name: Extract public assets + # run: | + # docker run -d --name helper registry.docker-box.richardwillis.info/${{ github.repository }}:latest tail -f /dev/null + # docker cp helper:/app/public . + # docker stop helper + # docker rm helper + + - name: Build + run: npm run build + env: + STRAPI_ENDPOINT: ${{ secrets.STRAPI_ENDPOINT }} - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v1 @@ -99,14 +115,24 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: us-east-1 - - name: Sync .next static assets to S3 - run: aws s3 sync .next/static s3://${{ secrets.AWS_S3_BUCKET }}/_next/static --cache-control public,max-age=31536000,immutable --size-only + - name: Sync static assets to S3 + run: | + aws s3 sync out/_next/static s3://${{ secrets.AWS_S3_BUCKET }}/_next/static --cache-control public,max-age=31536000,immutable --size-only - - name: Sync public assets to S3 - run: aws s3 sync public/site-assets s3://${{ secrets.AWS_S3_BUCKET }}/site-assets --cache-control public,max-age=31536000,immutable --size-only + - name: Sync data to S3 + run: | + aws s3 sync out/_next/data s3://${{ secrets.AWS_S3_BUCKET }}/_next/data --cache-control no-cache --size-only - - name: Restart Service + - name: Sync html files to S3 run: | - curl --fail -X POST "$DEPLOY_ENDPOINT" || exit 1 - env: - DEPLOY_ENDPOINT: '${{ secrets.DEPLOY_ENDPOINT }}' + aws s3 sync out s3://${{ secrets.AWS_S3_BUCKET }}/ --cache-control no-cache --size-only --exclude "*" --include "*.html" + + - name: Sync public assets to S3 + run: | + aws s3 sync public/site-assets s3://${{ secrets.AWS_S3_BUCKET }}/site-assets --cache-control public,max-age=31536000,immutable --size-only + + # - name: Restart Service + # run: | + # curl --fail -X POST "$DEPLOY_ENDPOINT" || exit 1 + # env: + # DEPLOY_ENDPOINT: '${{ secrets.DEPLOY_ENDPOINT }}'