Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
sprutton1 committed Jun 6, 2024
1 parent cff19fb commit 9a2c296
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 59 deletions.
57 changes: 0 additions & 57 deletions .github/workflows/deploy-service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,56 +33,7 @@ jobs:
aws-secret-access-key: ${{ secrets.secret_key }}
aws-region: us-east-1

- name: Deploy web
id: deploy-web
if: ${{ inputs.service == 'web' }}
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
- name: Deploy service
if: ${{ inputs.service != 'web' }}
run: |
check_version_exists() {
local version="$1"
Expand Down Expand Up @@ -126,11 +77,3 @@ jobs:
else
echo "Version $VERSION for $SERVICE not found in the artifacts registry. Skipping!"
fi
invalidate-cache:
if: ${{ inputs.service == 'web' }}
needs: deploy
uses: ./.github/workflows/invalidate-cache.yml
with:
environment: ${{ inputs.environment }}
secrets: inherit
43 changes: 43 additions & 0 deletions .github/workflows/deploy-services.yml
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
12 changes: 10 additions & 2 deletions .github/workflows/deploy-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
deploy-service:
needs: secrets
if: ${{ github.event.inputs.service != 'all' }}
uses: ./.github/workflows/deploy-service.yml
uses: ./.github/workflows/deploy-services.yml
with:
environment: ${{ github.event.inputs.environment }}
service: ${{ github.event.inputs.service }}
Expand All @@ -69,7 +69,7 @@ jobs:
fail-fast: false
matrix:
service: ["pinga", "rebaser", "sdf", "veritech", "web"]
uses: ./.github/workflows/deploy-service.yml
uses: ./.github/workflows/deploy-services.yml
with:
environment: ${{ github.event.inputs.environment }}
service: ${{ matrix.service }}
Expand All @@ -78,6 +78,14 @@ jobs:
access_key: ${{ secrets[needs.secrets.outputs.aws_access_key] }}
secret_key: ${{ secrets[needs.secrets.outputs.aws_secret_key] }}

invalidate-cache:
if: ${{ github.event.inputs.service == 'all' }}
needs: deploy
uses: ./.github/workflows/invalidate-cache.yml
with:
environment: ${{ inputs.environment }}
secrets: inherit

set-init:
needs: secrets
uses: ./.github/workflows/set-init-version.yml
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/deploy-web.yml
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

0 comments on commit 9a2c296

Please sign in to comment.