-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
141 additions
and
59 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: Deploy Services | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
type: string | ||
required: true | ||
description: "where to deploy" | ||
service: | ||
type: string | ||
required: true | ||
description: "service to deploy" | ||
version: | ||
type: string | ||
required: true | ||
description: "version to deploy" | ||
secrets: | ||
access_key: | ||
required: true | ||
secret_key: | ||
required: true | ||
|
||
jobs: | ||
deploy-service: | ||
name: Deploy Service | ||
if: ${{ github.event.inputs.service != 'web' }} | ||
uses: ./.github/workflows/deploy-service.yml | ||
with: | ||
environment: ${{ inputs.environment }} | ||
service: ${{ inputs.service }} | ||
version: ${{ inputs.version }} | ||
secrets: inherit | ||
|
||
deploy-web: | ||
name: Deploy Service | ||
if: ${{ github.event.inputs.service == 'web' }} | ||
uses: ./.github/workflows/deploy-web.yml | ||
with: | ||
environment: ${{ inputs.environment }} | ||
service: ${{ inputs.service }} | ||
version: ${{ inputs.version }} | ||
secrets: inherit |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
name: Deploy Web | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
environment: | ||
type: string | ||
required: true | ||
description: "where to deploy" | ||
service: | ||
type: string | ||
required: true | ||
description: "service to deploy" | ||
version: | ||
type: string | ||
required: true | ||
description: "version to deploy" | ||
secrets: | ||
access_key: | ||
required: true | ||
secret_key: | ||
required: true | ||
|
||
jobs: | ||
deploy: | ||
name: Deploy Web | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Configure AWS credentials for production | ||
uses: aws-actions/configure-aws-credentials@v2 | ||
with: | ||
aws-access-key-id: ${{ secrets.access_key }} | ||
aws-secret-access-key: ${{ secrets.secret_key }} | ||
aws-region: us-east-1 | ||
|
||
- name: Deploy web | ||
id: deploy | ||
run: | | ||
ENVIRONMENT="${{ inputs.environment }}" | ||
VERSION="${{ inputs.version }}" | ||
if docker manifest inspect "systeminit/web:$VERSION" >/dev/null 2>&1; then | ||
echo "Setting web to $VERSION." | ||
# we get the current task def for the service, update the image, and clean up the json so we can register it as a new task def | ||
task_definition_arn=$(aws ecs describe-services \ | ||
--cluster "${ENVIRONMENT}-cluster" \ | ||
--services "${ENVIRONMENT}-frontend" \ | ||
--query 'services[0].taskDefinition' \ | ||
--output text) | ||
new_task_definition=$(aws ecs describe-task-definition --task-definition "$task_definition_arn" | \ | ||
jq --arg IMAGE "systeminit/web:$VERSION" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | | ||
del(.taskDefinitionArn, .revision, .status, .requiresAttributes, .compatibilities, .registeredAt, .registeredBy)') | ||
aws ecs register-task-definition --cli-input-json "$new_task_definition" | ||
aws ecs update-service \ | ||
--cluster "${ENVIRONMENT}-cluster" \ | ||
--service "${ENVIRONMENT}-frontend" \ | ||
--task-definition "$ENVIRONMENT-web" \ | ||
--force-new-deployment | ||
while true; do | ||
deployment_status=$(aws ecs describe-services \ | ||
--cluster "${ENVIRONMENT}-cluster" \ | ||
--service "${ENVIRONMENT}-frontend" \ | ||
--query 'services[0].deployments[?status==`PRIMARY`].rolloutState' \ | ||
--output text) | ||
echo "Current deployment status: $deployment_status" | ||
if [[ "$deployment_status" == "COMPLETED" ]]; then | ||
echo "Service update completed successfully." | ||
break | ||
elif [[ "$deployment_status" == "FAILED" ]]; then | ||
echo "Service update failed." | ||
exit 1 | ||
else | ||
echo "Service update is still in progress. Waiting..." | ||
sleep 15 | ||
fi | ||
done | ||
else | ||
echo "Image systeminit/web:$VERSION not found on Docker Hub. Skipping!" | ||
fi | ||
invalidate-cache: | ||
needs: deploy | ||
uses: ./.github/workflows/invalidate-cache.yml | ||
with: | ||
environment: ${{ inputs.environment }} | ||
secrets: inherit |