Skip to content
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

Try upload html files #154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
161 changes: 91 additions & 70 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,96 @@ 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: Install NPM Packages
run: npm ci
env:
NPM_CONFIG_FUND: false
NPM_CONFIG_AUDIT: false
CI: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
# - name: Set up QEMU
# uses: docker/setup-qemu-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: 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 +119,15 @@ 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 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
- name: Sync app to S3
run: |
curl --fail -X POST "$DEPLOY_ENDPOINT" || exit 1
env:
DEPLOY_ENDPOINT: '${{ secrets.DEPLOY_ENDPOINT }}'
aws s3 sync out/_next/static s3://${{ secrets.AWS_S3_BUCKET }}/_next/static --cache-control public,max-age=31536000,immutable --size-only
aws s3 sync out/_next/data s3://${{ secrets.AWS_S3_BUCKET }}/_next/data --cache-control public,max-age=0,must-revalidate --size-only
aws s3 sync out s3://${{ secrets.AWS_S3_BUCKET }}/ --cache-control public,max-age=0,must-revalidate --size-only --exclude "*" --include "*.html"
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 }}'
20 changes: 0 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
},
"devDependencies": {
"@openapitools/openapi-generator-cli": "^2.4.12",
"@types/node-fetch": "^3.0.2",
"@types/react": "17.0.30",
"@types/react-dom": "^17.0.9",
"eslint": "^7.32.0",
Expand Down