From b289d4c049731777582b4855e0518a54d699c427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Wed, 17 Apr 2024 11:49:15 +0200 Subject: [PATCH] ci: sync build to s3 bucket We push changes to s3, and not to Docker Hub. --- .github/workflows/deploy_s3.yml | 36 +++++++++++++++++++++++++++++++++ .github/workflows/push.yml | 29 -------------------------- Makefile | 4 ++-- 3 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 .github/workflows/deploy_s3.yml delete mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/deploy_s3.yml b/.github/workflows/deploy_s3.yml new file mode 100644 index 0000000..416e141 --- /dev/null +++ b/.github/workflows/deploy_s3.yml @@ -0,0 +1,36 @@ +# Build site and sync with S3 +# To test this action with act (https://github.com/nektos/act) run: +# act --secret ACADEMY_S3_ACCESS_KEY_ID=xxx --secret ACADEMY_S3_SECRET_ACCESS_KEY=xxx --secret ACADEMY_S3_REGION=xxx --secret ACADEMY_S3_BUCKET=xxx +name: Deploy to S3 + +on: + push: + branches: [ master, main ] + +jobs: + deploy_to_s3: + name: Build and sync with S3 + runs-on: ubuntu-latest + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Install Python requirements + run: pip install -r requirements.txt + + - name: Install system requirements + run: apt update && apt install -y pandoc + + - name: Build site + run: make build + + # https://github.com/aws-actions/configure-aws-credentials?tab=readme-ov-file#assumerole-with-static-iam-credentials-in-repository-secrets + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.ACADEMY_S3_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.ACADEMY_S3_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.ACADEMY_S3_REGION }} + + - name: Sync build assets with S3 + run: aws s3 sync --delete _build/academy/ s3://${{ secrets.ACADEMY_S3_BUCKET }} diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 20fc020..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,29 +0,0 @@ -# https://docs.github.com/en/actions/publishing-packages/publishing-docker-images -name: Push - -on: - push: - branches: [ master, main ] - -jobs: - push_to_registry: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - steps: - - name: Check out the repo - uses: actions/checkout@v4 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: overhangio - password: ${{ secrets.DOCKER_OVERHANGIO_PASSWORD }} - - - name: Build and push Docker image - # https://github.com/docker/build-push-action - uses: docker/build-push-action@v5 - with: - context: . - file: ./Dockerfile - push: true - tags: docker.io/overhangio/academy:latest diff --git a/Makefile b/Makefile index 1d54f47..9ebe233 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ clean: ## Clean any existing site rm -rf contents/_build build: clean ## Build site - @python build.py - @cp -r layout/static _build/academy/static + python build.py + cp -r layout/static _build/academy/static watch: build ## Watch for changes and build site while true; do $(MAKE) wait-for-change build || true; done