Skip to content

Commit

Permalink
feat(ecs-deploy): make docker_image_tag optionnal
Browse files Browse the repository at this point in the history
  • Loading branch information
jdassonvil committed Apr 12, 2024
1 parent e129148 commit 4dba87e
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
42 changes: 35 additions & 7 deletions .github/workflows/ecs-deploy-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ on:
default: ""
docker_image_tag:
type: string
required: true
required: false
description: "DEPRECATED: use version instead"
environment:
type: string
required: true
Expand All @@ -37,6 +38,12 @@ on:
terraform_version:
type: string
required: false
use_version_as_docker_image_tag:
type: boolean
default: true
version:
type: string
require: false
wait_for_stabilization:
type: boolean
default: true
Expand Down Expand Up @@ -90,27 +97,48 @@ jobs:
- name: Terraform validate
run: terraform validate

- name: Get current version
id: current_version
- name: Get former version from ECS
if: inputs.docker_image_tag || inputs.use_version_as_docker_image_tag
id: ecs_lookup
run: |
CURRENT_TASK_DEFINITION="$(aws ecs list-task-definitions | jq --arg SERVICE "$SERVICE" --arg ENVIRONMENT "$ENV" -r -c '.taskDefinitionArns[] | select(contains($SERVICE + "-" + $ENVIRONMENT))')"
CURRENT_IMAGE_TAG="$(aws ecs describe-task-definition --task-definition "$CURRENT_TASK_DEFINITION" | jq --arg SERVICE "$SERVICE" -r -c '.taskDefinition.containerDefinitions[] | select(.name == $SERVICE) | .image' | cut -d':' -f2)"
echo "image_tag=$CURRENT_IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Get former version from Git
if: "! (inputs.docker_image_tag || inputs.use_version_as_docker_image_tag)"
uses: sencrop/github-workflows/actions/look-git-hash@master

- name: Notify deployment in progress
uses: sencrop/github-workflows/actions/notify-deployment-in-progress@master
with:
service: ${{ inputs.service }}
environment: ${{ inputs.environment }}
dd_api_key: ${{ secrets.DD_API_KEY }}
current_version: ${{ steps.current_version.outputs.image_tag }}
deployed_version: ${{ inputs.docker_image_tag }}
former_version: ${{ steps.ecs_lookup.outputs.image_tag || steps.git_hash.output.previous }}
new_version: ${{ inputs.docker_image_tag || steps.git_hash.output.current }}
slack_bot_token: ${{ secrets.SLACK_BOT_TOKEN }}

# TODO: remove this step once docker_image_tag has been removed
- name: Build tf_vars (using docker_image_tag)
if: inputs.docker_image_tag
id: tf_vars
run : |

Check failure on line 127 in .github/workflows/ecs-deploy-v2.yml

View workflow job for this annotation

GitHub Actions / lint

127:12 [colons] too many spaces before colon
TV_VAR_DOCKER_IMAGE_TAG="-var docker_image_tag=${{ inputs.docker_image_tag }}"
echo "docker_image_tag=$TF_VAR_DOCKER_IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Build tf_vars (using version)
if: "! inputs.docker_image_tag && inputs.use_version_as_docker_image_tag"
id: tf_vars
run : |

Check failure on line 134 in .github/workflows/ecs-deploy-v2.yml

View workflow job for this annotation

GitHub Actions / lint

134:12 [colons] too many spaces before colon
TV_VAR_DOCKER_IMAGE_TAG="-var docker_image_tag=${{ inputs.version }}"
echo "docker_image_tag=$TF_VAR_DOCKER_IMAGE_TAG" >> "$GITHUB_OUTPUT"
- name: Terraform apply
run: |
# shellcheck disable=SC2086
terraform apply -var "docker_image_tag=${DOCKER_IMAGE_TAG}" -var-file="${ENV}.tfvars" -auto-approve -input=false ${EXTRA_ARGS}
terraform apply ${{ steps.tf_vars.output.docker_image_tag }} -var-file ${ENV}.tfvars -auto-approve -input=false ${EXTRA_ARGS}
- name: Wait for stabilization
if: ${{ inputs.wait_for_stabilization }}
Expand Down
13 changes: 13 additions & 0 deletions actions/lookup-git-hash/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: "Lookup git hash"

runs:
using: "composite"
steps:
- name: Lookup Git hash
id: git_hash
run: |
REF="$(git rev-parse --short HEAD)"
PREVIOUS_REF="$(git rev-parse --short HEAD~1)"
echo "current=$REF" >> "${GITHUB_OUTPUT}"
echo "previous=$PREVIOUS_REF" >> "${GITHUB_OUTPUT}"
13 changes: 13 additions & 0 deletions actions/lookup-git-tag/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
name: "Lookup git tag"

runs:
using: "composite"
steps:
- name: Get version from tags
id: git_tag
run: |
REF="${GITHUB_REF#refs/tags/}"
PREVIOUS_REF="$(git tag -l 'v*' --sort=-v:refname | head -n2 | tail -n1)"
echo "current=$REF" >> "${GITHUB_OUTPUT}"
echo "previous=$PREVIOUS_REF" >> "${GITHUB_OUTPUT}"
12 changes: 9 additions & 3 deletions actions/notify-deployment-in-progress/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ description: "Track a deployment in progress"
inputs:
current_version:
type: string
required: true
description: "DEPRECATED: use new_version instead"
dd_api_key:
type: string
required: true
deployed_version:
type: string
required: true
description: "DEPRECATED: use former_version instead"
former_version:
type: string
deployed_version:
type: string
environment:
type: string
required: true
new_version:
type: string
service:
type: string
required: true
Expand All @@ -35,7 +41,7 @@ runs:
if: inputs.environment == 'production' && inputs.slack_notify == 'true'
with:
channel-id: ${{ inputs.slack_channel }}
slack-message: ":ship: New deployment of `${{ inputs.service }}` (version `${{ inputs.deployed_version }}`) in progress (<${{ github.server_url }}/${{ github.repository }}/compare/${{ inputs.current_version }}...${{ inputs.deployed_version }}|CHANGELOG>)"
slack-message: ":ship: New deployment of `${{ inputs.service }}` (version `${{ inputs.new_version || inputs.deployed_version }}`) in progress (<${{ github.server_url }}/${{ github.repository }}/compare/${{ inputs.former_version || inputs.current_version }}...${{ inputs.new_version || inputs.deployed_version }}|CHANGELOG>)"
env:
SLACK_BOT_TOKEN: ${{ inputs.SLACK_BOT_TOKEN }}

Expand Down

0 comments on commit 4dba87e

Please sign in to comment.