Skip to content

Commit

Permalink
feat: schedule_k8s_deploy github action (#213)
Browse files Browse the repository at this point in the history
make script executable

Added env to deploy-image

use gh_environment

quoted environment

fix: editorial

fix: editorial

uncomment ecs job and default to main branch for schedule_k8s_deploy
  • Loading branch information
3benbox authored Jan 10, 2024
1 parent 58dc5b6 commit a6ad028
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ jobs:
# For commit deployments, the target is the same as the tag (i.e. the commit hash).
deploy_target="$deploy_tag"
fi
make DEPLOY_ENV="$deploy_env" DEPLOY_TARGET="$deploy_target" DEPLOY_TAG="$deploy_tag" MANUAL_DEPLOY="true" schedule-deployment
make DEPLOY_ENV="$deploy_env" DEPLOY_TARGET="$deploy_target" DEPLOY_TAG="$deploy_tag" MANUAL_DEPLOY="true" schedule-ecs-deployment
-
name: Schedule k8s deployment
run: |
deploy_env="${{ github.event.inputs.environment }}"
deploy_tag="${{ github.event.inputs.tag }}"
# If this workflow was run for a release, indicate that this is a release deployment.
if [[ ${{ contains(github.event.head_commit.message, 'chore: Release') }} == 'true' ]]; then
deploy_tag=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"')
fi
make DEPLOY_ENV="$deploy_env" DEPLOY_TAG="$deploy_tag" schedule-k8s-deployment
12 changes: 11 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,14 @@ jobs:
deploy_target="release"
deploy_tag=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"')
fi
make DEPLOY_ENV="${{ matrix.network }}" DEPLOY_TARGET="$deploy_target" DEPLOY_TAG="$deploy_tag" schedule-deployment
make DEPLOY_ENV="${{ matrix.network }}" DEPLOY_TARGET="$deploy_target" DEPLOY_TAG="$deploy_tag" schedule-ecs-deployment
-
name: Schedule k8s deployment
run: |
deploy_tag=$(echo ${{ github.SHA }} | head -c 12)
# If this workflow was run for a release, indicate that this is a release deployment.
if [[ ${{ contains(github.event.head_commit.message, 'chore: Release') }} == 'true' ]]; then
deploy_tag=$(cargo metadata --format-version=1 --no-deps | jq '.packages[0].version' | tr -d '"')
fi
make DEPLOY_ENV="${{ matrix.network }}" DEPLOY_TAG="$deploy_tag" schedule-k8s-deployment
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ run:
publish-docker:
./ci-scripts/publish.sh

.PHONY: schedule-deployment
schedule-deployment:
./ci-scripts/deploy.sh "${DEPLOY_ENV}" "${DEPLOY_TARGET}" "${DEPLOY_TAG}" "${MANUAL_DEPLOY}"
.PHONY: schedule-ecs-deployment
schedule-ecs-deployment:
./ci-scripts/schedule_ecs_deploy.sh "${DEPLOY_ENV}" "${DEPLOY_TARGET}" "${DEPLOY_TAG}" "${MANUAL_DEPLOY}"

.PHONY: schedule-k8s-deployment
schedule-k8s-deployment:
./ci-scripts/schedule_k8s_deploy.sh "${DEPLOY_ENV}" "${DEPLOY_TAG}"
File renamed without changes.
41 changes: 41 additions & 0 deletions ci-scripts/schedule_k8s_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

id=$(uuidgen)
job_id=$(uuidgen)
now=$(date +%s%N)
ttl=$(date +%s -d "14 days")
image=public.ecr.aws/r5b3e0r5/3box/ceramic-one:${2-latest}
branch=${TEST_BRANCH-main}
network=${1-dev}
environment=ceramic-v4-${network}

docker run --rm -i \
-e "AWS_REGION=$AWS_REGION" \
-e "AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID" \
-e "AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY" \
-v ~/.aws:/root/.aws \
-v "$PWD":/aws \
amazon/aws-cli dynamodb put-item --table-name "ceramic-$network-ops" --item \
"{ \
\"id\": {\"S\": \"$id\"}, \
\"job\": {\"S\": \"$job_id\"}, \
\"ts\": {\"N\": \"$now\"}, \
\"ttl\": {\"N\": \"$ttl\"}, \
\"stage\": {\"S\": \"queued\"}, \
\"type\": {\"S\": \"workflow\"}, \
\"params\": { \
\"M\": { \
\"name\": {\"S\": \"Deploy CERAMIC ONE\"}, \
\"org\": {\"S\": \"3box\"}, \
\"repo\": {\"S\": \"ceramic-infra\"}, \
\"ref\": {\"S\": \"$branch\"}, \
\"workflow\": {\"S\": \"update_image.yml\"}, \
\"inputs\": { \
\"M\": { \
\"ceramic_one_image\": {\"S\": \"$image\"}, \
\"environment\": {\"S\": \"$environment\"} \
} \
} \
} \
} \
}"

0 comments on commit a6ad028

Please sign in to comment.