Skip to content

Commit 312898d

Browse files
committed
Pull main
2 parents ae73655 + bca538b commit 312898d

7 files changed

Lines changed: 313 additions & 86 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: '🚀 Deploy ECS service'
2+
description: 'Deploy service on ECS with terraform'
3+
4+
inputs:
5+
AWS_REGION:
6+
description: 'The AWS region to use'
7+
required: true
8+
default: eu-west-1
9+
ENVIRONMENT:
10+
description: 'Enter the environment.'
11+
required: true
12+
AWS_DEPLOYMENT_ROLE:
13+
description: 'The ARN of the AWS github-ci role the role to use for deployment'
14+
required: true
15+
TERRAFORM_VERSION:
16+
description: 'The version of Terraform to use'
17+
required: false
18+
default: 1.9.8
19+
TERRAFORM_PATH:
20+
description: "The path to the terraform files"
21+
required: false
22+
default: "terraform"
23+
24+
runs:
25+
using: 'composite'
26+
steps:
27+
- name: Setup Terraform
28+
uses: hashicorp/setup-Terraform@v3
29+
with:
30+
terraform_version: ${{ inputs.TERRAFORM_VERSION }}
31+
32+
- name: Terraform version
33+
shell: bash
34+
run: terraform --version
35+
36+
- name: 'Configure AWS Credentials'
37+
uses: aws-actions/configure-aws-credentials@v4
38+
with:
39+
role-to-assume: ${{ inputs.AWS_DEPLOYMENT_ROLE }}
40+
aws-region: ${{ inputs.AWS_REGION }}
41+
42+
- name: Terraform apply
43+
shell: bash
44+
run: |
45+
cd ${{ inputs.TERRAFORM_PATH }}/${{ inputs.ENVIRONMENT }}
46+
terraform init
47+
terraform apply -auto-approve

.github/actions/build-and-push-image/action.yml

Lines changed: 87 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,98 @@ inputs:
99
description: "The ARN of the AWS github-ci role to use to push to ECR"
1010
required: true
1111
ECR_REPOSITORY:
12-
description: "The name of the ECR repository"
13-
required: true
12+
description: "The name of the ECR repository. Required if ECR_REPOSITORIES is not set"
13+
required: false
14+
ECR_REPOSITORIES:
15+
description: "The names of the ECR repositories. Required if ECR_REPOSITORY is not set"
16+
required: false
1417
WORKING_DIRECTORY:
1518
description: "The working directory to use"
1619
required: false
1720
default: "."
21+
CUSTOM_BUILD_SCRIPT:
22+
description: "The custom build script to use"
23+
required: false
1824

1925
runs:
2026
using: "composite"
2127
steps:
22-
- name: 🔐 Configure AWS credentials
23-
uses: aws-actions/configure-aws-credentials@v4
24-
with:
25-
role-to-assume: ${{ inputs.AWS_ROLE_ARN }}
26-
role-session-name: GitHub-Action-Role
27-
aws-region: ${{ inputs.AWS_REGION }}
28-
29-
- name: 🔓 Login to Amazon ECR
30-
id: login-ecr
31-
uses: aws-actions/amazon-ecr-login@v2
32-
33-
- name: 🐳 Docker Metadata
34-
uses: docker/metadata-action@v5
35-
id: meta
36-
with:
37-
images: "${{ steps.login-ecr.outputs.registry }}/${{ inputs.ECR_REPOSITORY }}"
38-
tags: |
39-
latest
40-
type=sha,prefix=sha-,format=long
41-
type=ref,event=branch
42-
type=ref,event=pr
43-
type=ref,event=tag
44-
45-
- name: 🏗️ Build and push
46-
if: steps.check-image-tag.outputs.exists != 'true'
47-
uses: docker/build-push-action@v5
48-
with:
49-
push: true
50-
tags: ${{ steps.meta.outputs.tags }}
51-
labels: ${{ steps.meta.outputs.labels }}
52-
context: ${{ inputs.WORKING_DIRECTORY }}
28+
- name: 🔐 Configure AWS credentials
29+
uses: aws-actions/configure-aws-credentials@v4
30+
with:
31+
role-to-assume: ${{ inputs.AWS_ROLE_ARN }}
32+
role-session-name: GitHub-Action-Role
33+
aws-region: ${{ inputs.AWS_REGION }}
34+
35+
- name: 🔓 Login to Amazon ECR
36+
id: login-ecr
37+
uses: aws-actions/amazon-ecr-login@v2
38+
39+
- name: 🧩 Parse ECR repositories
40+
id: parse
41+
shell: bash
42+
run: |
43+
if [ -n "${{ inputs.ECR_REPOSITORIES }}" ]; then
44+
repos=$(echo "${{ inputs.ECR_REPOSITORIES }}" | tr ',' '\n')
45+
elif [ -n "${{ inputs.ECR_REPOSITORY }}" ]; then
46+
repos="${{ inputs.ECR_REPOSITORY }}"
47+
else
48+
echo "Error: Either ECR_REPOSITORY or ECR_REPOSITORIES must be provided."
49+
exit 1
50+
fi
51+
52+
echo "repos<<EOF" >> $GITHUB_OUTPUT
53+
echo "$repos" >> $GITHUB_OUTPUT
54+
echo "EOF" >> $GITHUB_OUTPUT
55+
56+
# Build a multiline string of full ECR paths
57+
images=""
58+
for repo in $repos; do
59+
images="$images\n${{ steps.login-ecr.outputs.registry }}/${repo}"
60+
done
61+
62+
# Write images to this step's output
63+
echo "images<<EOF" >> $GITHUB_OUTPUT
64+
echo -e "$images" >> $GITHUB_OUTPUT
65+
echo "EOF" >> $GITHUB_OUTPUT
66+
67+
- name: 🐳 Docker Metadata
68+
uses: docker/metadata-action@v5
69+
id: meta
70+
with:
71+
images: "${{ steps.parse.outputs.images }}"
72+
tags: |
73+
latest
74+
type=sha,prefix=sha-,format=long
75+
type=ref,event=branch
76+
type=ref,event=pr
77+
type=ref,event=tag
78+
79+
- name: 🏗️ Build and push
80+
if: ${{ !inputs.CUSTOM_BUILD_SCRIPT }}
81+
uses: docker/build-push-action@v5
82+
with:
83+
push: true
84+
tags: ${{ steps.meta.outputs.tags }}
85+
labels: ${{ steps.meta.outputs.labels }}
86+
context: ${{ inputs.WORKING_DIRECTORY }}
87+
88+
- name: 🏗️ Build and push images with custom script
89+
if: ${{ inputs.CUSTOM_BUILD_SCRIPT }}
90+
shell: bash
91+
working-directory: ${{ inputs.WORKING_DIRECTORY }}
92+
run: |
93+
${{ inputs.CUSTOM_BUILD_SCRIPT }}
94+
repos="${{ steps.parse.outputs.repos }}"
95+
tags="${{ steps.meta.outputs.tags }}"
96+
for repo in $repos; do
97+
echo "Processing repository: $repo"
98+
for tag in $tags; do
99+
if [[ $tag == *"$repo"* ]]; then
100+
echo "Tagging and pushing: $tag for image $repo"
101+
docker tag "$repo" "$tag"
102+
docker push "$tag"
103+
fi
104+
done
105+
done
106+

.github/actions/deploy-ecs-service/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ runs:
6363
terraform init
6464
for resource in $(echo '${{ inputs.PRE_APPLIED_RESOURCES }}' | jq -r '.[]'); do
6565
echo "Applying target: $resource"
66-
terraform apply -auto-approve -target="$resource"
66+
terraform apply -auto-approve -target="$resource" -var 'image_tag=${{ inputs.IMAGE_TAG }}'
6767
done
6868
terraform apply -auto-approve -var 'image_tag=${{ inputs.IMAGE_TAG }}'
6969
7070
- name: Force new deployment
7171
shell: bash
72-
if: ${{ inputs.FORCE_NEW_DEPLOYMENT }}
72+
if: ${{ inputs.FORCE_NEW_DEPLOYMENT == 'true' && inputs.SERVICE_NAME && inputs.CLUSTER_NAME }}
7373
run: |
7474
aws ecs update-service \
7575
--cluster ${{ inputs.CLUSTER_NAME }} \
@@ -78,7 +78,7 @@ runs:
7878
7979
- name: Wait for stable
8080
shell: bash
81-
if: ${{ inputs.FORCE_NEW_DEPLOYMENT }}
81+
if: ${{ inputs.FORCE_NEW_DEPLOYMENT == 'true' && inputs.SERVICE_NAME && inputs.CLUSTER_NAME }}
8282
run: |
8383
aws ecs wait services-stable \
8484
--cluster ${{ inputs.CLUSTER_NAME }} \

.github/actions/retag-docker-image/action.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ inputs:
99
description: 'The ARN of the AWS github-ci role to use to push to ECR'
1010
required: true
1111
ECR_REPOSITORY:
12-
description: 'The name of the ECR repository'
13-
required: true
12+
description: "The name of the ECR repository. Required if ECR_REPOSITORIES is not set"
13+
required: false
14+
ECR_REPOSITORIES:
15+
description: "The names of the ECR repositories. Required if ECR_REPOSITORY is not set"
16+
required: false
1417
VERSION_TAG:
1518
description: 'The version tag to apply to the image'
1619
required: true
@@ -30,7 +33,17 @@ runs:
3033
uses: aws-actions/amazon-ecr-login@v2
3134

3235
- name: 🔖 Re-tag Image
36+
if: ${{ inputs.ECR_REPOSITORY }}
3337
shell: bash
3438
run: |
3539
MANIFEST=$(aws ecr batch-get-image --repository-name ${{ inputs.ECR_REPOSITORY }} --image-ids imageTag=sha-${{ github.sha }} --query 'images[].imageManifest' --output text)
3640
aws ecr put-image --repository-name ${{ inputs.ECR_REPOSITORY }} --image-tag ${{ inputs.VERSION_TAG }} --image-manifest "$MANIFEST"
41+
42+
- name: 🔖 Re-tag Images
43+
if: ${{ inputs.ECR_REPOSITORIES }}
44+
shell: bash
45+
run: |
46+
for repo in ${{ inputs.ECR_REPOSITORIES }}; do
47+
MANIFEST=$(aws ecr batch-get-image --repository-name $repo --image-ids imageTag=sha-${{ github.sha }} --query 'images[].imageManifest' --output text)
48+
aws ecr put-image --repository-name $repo --image-tag ${{ inputs.VERSION_TAG }} --image-manifest "$MANIFEST"
49+
done
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Unify Services
2+
description: Unifies one or more services into a single output.
3+
author: Your Name
4+
5+
inputs:
6+
service_name:
7+
description: A single service name
8+
required: false
9+
services:
10+
description: Multiple services (JSON array of objects)
11+
required: false
12+
13+
outputs:
14+
final_services:
15+
value: ${{ steps.unify-services.outputs.final_services }}
16+
description: The unified list of services (JSON array of objects)
17+
18+
runs:
19+
using: composite
20+
steps:
21+
- name: Unify service inputs
22+
id: unify-services
23+
shell: bash
24+
run: |
25+
if [ -n "${{ inputs.service_name }}" ] && [ -z "${{ inputs.services }}" ]; then
26+
echo 'final_services=[{"directory":".","name":"${{ inputs.service_name }}"}]' >> $GITHUB_OUTPUT
27+
28+
elif [ -z "${{ inputs.service_name }}" ] && [ -n "${{ inputs.services }}" ]; then
29+
echo 'final_services=${{ inputs.services }}' >> $GITHUB_OUTPUT
30+
31+
else
32+
echo "ERROR: Exactly one of 'service_name' or 'services' must be set." >&2
33+
exit 1
34+
fi

0 commit comments

Comments
 (0)