Skip to content

Commit

Permalink
Adding hot-upgrade CI used by manual deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagoesteves committed Jun 4, 2024
1 parent 860d8c6 commit 96081a4
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 6 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/full-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ jobs:
version-file: .tool-versions
version-type: strict

- name: Capture GITHUB_SHORT_SHA
run: |
GITHUB_SHORT_SHA=$(git rev-parse --short ${{ github.sha }})
echo "GITHUB_SHORT_SHA=${GITHUB_SHORT_SHA}" >> $GITHUB_ENV
- name: Update project mix version
run: |
sed -i "s/.*version:.*/ version: \"${{ inputs.tag }}\",/" mix.exs
Expand Down
85 changes: 85 additions & 0 deletions .github/workflows/hot-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Deploy a hot-upgrade package/version to AWS

on:
workflow_call:
inputs:
tag:
required: true
type: string

env:
MIX_ENV: prod

jobs:
build:
name: Building a release and publishing it at AWS
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup BEAM
uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict

- name: Retrieve the deployed current.json
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: "sa-east-1"
source: "s3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/versions/calori/${{ secrets.CLOUD_ENV_NAME }}/current.json"
dest: "./s3-current.json"

- name: Compile the current deployed version
run: |
VERSION=$(cat s3-current.json | jq '.version' | tr -d '"')
HASH=$(cat s3-current.json | jq '.hash' | tr -d '"')
echo ${VERSION} ${HASH}
git checkout ${HASH}
sed -i "s/.*version:.*/ version: \"${VERSION}\",/" mix.exs
mix deps.get
mix compile
mix assets.deploy
mix release
echo "Return to the current branch head: ${GITHUB_SHA}"
git checkout ${GITHUB_SHA}
- name: Update project mix version
run: |
sed -i "s/.*version:.*/ version: \"${{ inputs.tag }}\",/" mix.exs
- name: Create Release file version
run: |
echo "{\"version\":\"${{ inputs.tag }}\",\"hash\":\"${GITHUB_SHA}\"}" | jq > current.json
- name: Install Elixir dependencies
run: mix do deps.get, compile

- name: Assets Deploy
run: mix assets.deploy

- name: Generate a Release
run: mix release

- name: Copy a release file to the s3 distribution folder
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: "sa-east-1"
source: "_build/prod/calori-${{ inputs.tag }}.tar.gz"
dest: "s3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/dist/calori/calori-${{ inputs.tag }}.tar.gz"

- name: Copy a version file to the s3 version folder
uses: prewk/s3-cp-action@v2
with:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws_region: "sa-east-1"
source: "current.json"
dest: "s3://calori-${{ secrets.CLOUD_ENV_NAME }}-distribution/versions/calori/${{ secrets.CLOUD_ENV_NAME }}/current.json"
11 changes: 10 additions & 1 deletion .github/workflows/manual-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ jobs:
tag: ${{ env.PROJ_TAG }}
message: "Created ${{ inputs.deployment }} tag ${{ env.PROJ_TAG }}"

deploy:
deploy-full-deployment:
if: inputs.deployment == 'full-deployment'
needs: create-tag
uses: ./.github/workflows/full-deployment.yaml
with:
tag: ${{ needs.create-tag.outputs.tag }}
secrets: inherit

deploy-hot-upgrade:
if: inputs.deployment == 'hot-upgrade'
needs: create-tag
uses: ./.github/workflows/hot-upgrade.yaml
with:
tag: ${{ needs.create-tag.outputs.tag }}
secrets: inherit

0 comments on commit 96081a4

Please sign in to comment.