Skip to content

Commit 69c0335

Browse files
committed
Enable blue/green deployment
1 parent 5f12cc3 commit 69c0335

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

.github/workflows/main.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ on:
1616
- cron: "0 0 * * 0" # weekly
1717

1818
env:
19-
BUILD_TAG: "build-engine-api:latest"
19+
BUILD_TAG: "build-engine-api:${{ github.sha }}"
2020

2121
jobs:
2222
build:
@@ -37,6 +37,13 @@ jobs:
3737
run: |
3838
echo "COMPOSER_AUTH={\"github-oauth\":{\"github.com\":\""${{ secrets.GITHUB_TOKEN }}\""}}" > local.env
3939
40+
- name: Install dependencies
41+
run: |
42+
echo "Installing ecs-deploy script..."
43+
mkdir -p $HOME/.local/bin
44+
curl -o $HOME/.local/bin/ecs-deploy https://raw.githubusercontent.com/silinternational/ecs-deploy/master/ecs-deploy
45+
chmod +x $HOME/.local/bin/ecs-deploy
46+
4047
- name: Tests
4148
run: |
4249
make test
@@ -54,7 +61,9 @@ jobs:
5461
run: |
5562
if [[ "${GITHUB_HEAD_REF}" != "" ]]; then BRANCH="${GITHUB_HEAD_REF}"; else BRANCH="${GITHUB_REF_NAME}"; fi
5663
case $BRANCH in develop) DOCKER_TAG="staging" ;; master) DOCKER_TAG="production" ;; *) DOCKER_TAG="${BRANCH//\//-}" ;; esac
64+
case $BRANCH in develop) ECS_CLUSTER="scriptoria-stg";; master) ECS_CLUSTER="scriptoria-prd" ;; *) ECS_CLUSTER="none" ;; esac
5765
echo "DockerTag=${DOCKER_TAG}" >> $GITHUB_OUTPUT
66+
echo "EcsCluster=${ECS_CLUSTER}" >> $GITHUB_OUTPUT
5867
5968
- name: Login to GitHub Container Registry
6069
uses: docker/login-action@v2
@@ -84,8 +93,18 @@ jobs:
8493

8594
- name: Push to AWS ECR (SIL)
8695
run: |
87-
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
96+
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
97+
docker tag ${{ env.BUILD_TAG }} "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ github.sha }}"
8898
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ steps.branch.outputs.DockerTag }}"
99+
docker push "${{ steps.ecr_sil.outputs.registry }}/appbuilder-buildengine-api:${{ github.sha }}"
100+
101+
- name: Deploy to ECS (SIL)
102+
if: ${{ steps.branch.outputs.EcsCluster != 'none' }}
103+
run: |
104+
echo "Deploying ${{ github.sha }} to ${{ steps.branch.outputs.EcsCluster }}"
105+
# Deploy to ECS cluster with service name 'build-engine', setting all images to the latest tag
106+
ecs-deploy -c ${{ steps.branch.outputs.EcsCluster }} -n build-engine -i ignore -to ${{ github.sha }} --max-definitions 20 --timeout 600
107+
echo "Deployment initiated successfully."
89108
90109
- name: Clean up older packages
91110
uses: actions/delete-package-versions@v4

0 commit comments

Comments
 (0)