Skip to content

Commit

Permalink
Merge pull request #2176 from iFixit/strapi--deploy-with-actions
Browse files Browse the repository at this point in the history
Strapi: Deploy with actions
  • Loading branch information
mlahargou authored Jan 3, 2024
2 parents 5d7c686 + 222d782 commit 70319a9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
30 changes: 4 additions & 26 deletions .github/workflows/deploy-strapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,16 @@ on:
push:
branches:
- main
- deploy-strapi-test*
paths:
- 'backend/**'

# @see https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#adding-permissions-settings
permissions:
id-token: write # Required to allow the JWT to be requested from GitHub's OIDC provider
contents: read # Required for actions/checkout

jobs:
build-strapi:
runs-on: ubuntu-latest
runs-on:
group: react-commerce-production-deploy
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: 'arn:aws:iam::884681002735:role/github_actions/github-actions-role'
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Build, Tag, and Push Base Image to Amazon ECR Private
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
DOCKER_TAG: strapi:${{ github.sha }}
run: |
cd backend
docker build -t "$DOCKER_TAG" .
docker tag "$DOCKER_TAG" "$REGISTRY/$DOCKER_TAG"
docker push "$REGISTRY/$DOCKER_TAG"
- name: Deploy Strapi
run: backend/strapi-deploy-actions
31 changes: 31 additions & 0 deletions backend/strapi-deploy-actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

set -o pipefail -e nounset

export STRAPI_COMMIT=$(git rev-parse HEAD)
DEPLOY_TAG=last-strapi-deploy
SLACK="/home/ifixit/Code/Exec/slackAnnounce.php"

git fetch --tags --quiet

SUBJECT=$(git rev-list --format="%s" --max-count=1 "$STRAPI_COMMIT" | tail -1)
COMMIT_LINK="<https://$BUILD_REPO/commit/$STRAPI_COMMIT|${SUBJECT}>"
DEPLOY_LOG_TS=$($SLACK --message="Strapi Deploy: Deploying ${COMMIT_LINK} - 📃 <$BUILD_LOG_URL|build log>")
$SLACK --thread_ts="$DEPLOY_LOG_TS" --message="Building Docker image"

strapi_dir="$(git rev-parse --show-toplevel)/backend"
cd "$strapi_dir"
./build-docker-and-push

$SLACK --thread_ts="$DEPLOY_LOG_TS" --message="Deploying"
# Yes, capistrano is only available in our main repo...
# This wont be a problem when these repos are joined though :-)
cd /home/ifixit/Code
cap prod strapi:deploy

## Deploy Tag
cd "$strapi_dir"
git tag -f "$DEPLOY_TAG" "$STRAPI_COMMIT"
git push -f origin "$DEPLOY_TAG"

$SLACK --thread_ts="$DEPLOY_LOG_TS" --message="Deploy complete!"

2 comments on commit 70319a9

@vercel
Copy link

@vercel vercel bot commented on 70319a9 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-commerce – ./frontend

react-commerce-ifixit.vercel.app
react-commerce-git-main-ifixit.vercel.app
react-commerce.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 70319a9 Jan 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

react-commerce-prod – ./frontend

react-commerce-prod-git-main-ifixit.vercel.app
react-commerce-prod-ifixit.vercel.app
react-commerce-prod.vercel.app

Please sign in to comment.