Skip to content

Commit

Permalink
Try upload html files
Browse files Browse the repository at this point in the history
  • Loading branch information
badsyntax committed Oct 17, 2021
1 parent aa93d90 commit c834e5b
Showing 1 changed file with 94 additions and 68 deletions.
162 changes: 94 additions & 68 deletions .github/workflows/prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
push:
branches:
- master

pull_request:
branches: [master]
# release:
# types: [published]

Expand All @@ -18,79 +21,92 @@ jobs:
steps:
- uses: actions/[email protected]

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Node.js
uses: actions/[email protected]
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
with:
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
Expand All @@ -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 }}'

0 comments on commit c834e5b

Please sign in to comment.