feat: impl feature flags #130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Container ECR build + deploy | |
on: | |
push: | |
branches: | |
- main | |
- demo | |
permissions: | |
id-token: write | |
contents: read | |
jobs: | |
setup-env: | |
if: github.repository == 'UnlockedLabs/UnlockEdv2' || github.repository == 'PThorpe92/UnlockEdv2' | |
runs-on: ubuntu-latest | |
outputs: | |
changes: ${{ steps.check-changes.outputs.changes }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 3 | |
- id: check-changes | |
run: | | |
paths=("frontend/" "backend/" "provider-middleware/" "backend/tasks") | |
changes="" | |
for path in "${paths[@]}"; do | |
count=$(git diff --name-only HEAD~1 | grep "^${path}" | wc -l) | |
changes+="${path}:${count}," | |
done | |
echo "changes=${changes}" >> $GITHUB_OUTPUT | |
- name: Debug changes | |
run: echo "${{ steps.check-changes.outputs.changes }}" | |
build-and-push: | |
if: github.repository == 'UnlockedLabs/UnlockEdv2' || github.repository == 'PThorpe92/UnlockEdv2' | |
needs: setup-env | |
runs-on: ubuntu-latest | |
env: | |
CHANGES: ${{ needs.setup-env.outputs.changes }} | |
outputs: | |
deployments: ${{ steps.determine-deployments.outputs.deployments }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.AWS_IAM_ROLE }} | |
aws-region: us-west-2 | |
mask-aws-account-id: true | |
- name: Log in to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- id: build-images | |
run: | | |
deployments=() | |
for entry in ${{ needs.setup-env.outputs.changes }}; do | |
path=$(echo $entry | cut -d':' -f1) | |
count=$(echo $entry | cut -d':' -f2) | |
if [[ $count -ne 0 ]]; then | |
case $path in | |
"frontend/") | |
echo "Building frontend image" | |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/frontend:latest --push frontend/. | |
deployments+=("frontend") | |
;; | |
"backend/") | |
echo "Building backend image" | |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/unlockedv2:latest --push -f backend/Dockerfile . | |
deployments+=("server") | |
;; | |
"provider-middleware/") | |
echo "Building middleware image" | |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/provider_middleware:latest --push -f provider-middleware/Dockerfile . | |
deployments+=("provider-service") | |
;; | |
"backend/tasks") | |
echo "Building scheduler image" | |
docker buildx build --platform linux/amd64 -t=${{ steps.login-ecr.outputs.registry }}/cron_tasks:latest --push -f backend/tasks/Dockerfile . | |
deployments+=("cron-tasks") | |
;; | |
esac | |
fi | |
done | |
echo "deployments=${deployments[*]}" >> $GITHUB_OUTPUT | |
restart-deployments: | |
if: github.repository == 'UnlockedLabs/UnlockEdv2' || github.repository == 'PThorpe92/UnlockEdv2' | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
env: | |
BASTION_HOST: ${{ secrets.BASTION_HOST }} | |
SSH_KEY: ${{ secrets.SSH_KEY }} | |
steps: | |
- name: Restart Deployments | |
run: | | |
deployments="${{ needs.build-and-push.outputs.deployments }}" | |
if [[ -z "$deployments" ]]; then | |
echo "No deployments need restarting." | |
exit 0 | |
fi | |
if [[ "${GITHUB_REF}" == "refs/heads/demo" ]]; then | |
CONTEXT="demo" | |
elif [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then | |
CONTEXT="staging" | |
else | |
echo "Unknown branch: ${GITHUB_REF}. No deployments restarted." | |
exit 1 | |
fi | |
ssh -i "$SSH_KEY" -o StrictHostKeyChecking=no "$BASTION_HOST" "bash -s" <<EOF | |
rollout.sh $CONTEXT $deployments | |
EOF |