Skip to content

Merge pull request #19 from 2024-Iris/repository #60

Merge pull request #19 from 2024-Iris/repository

Merge pull request #19 from 2024-Iris/repository #60

Workflow file for this run

name: Deploy to Amazon ECS
on:
push:
branches: [ "main" ]
env:
AWS_REGION: ${{ secrets.AWS_REGION }}
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }}
ECS_SERVICE: ${{ secrets.ECS_SERVICE }}
ECS_CLUSTER: ${{ secrets.ECS_CLUSTER }}
ECS_TASK_DEFINITION: ${{ secrets.ECS_TASK_DEFINITION }}
CONTAINER_NAME: ${{ secrets.CONTAINER_NAME }}
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
token: ${{ secrets.GH_ISSUEFY_ROY_TOKEN }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Semantic Release
run: |
OUTPUT=$(npx semantic-release --no-ci)
echo "$OUTPUT"
VERSION=$(echo "$OUTPUT" | grep -oP 'Published release \K[0-9.]+')
if [ ! -z "$VERSION" ]; then
echo "SEMANTIC_VERSION=$VERSION" >> $GITHUB_ENV
else
echo "Error: SEMANTIC_VERSION not extracted" && exit 1
fi
env:
GH_TOKEN: ${{ secrets.GH_ISSUEFY_ROY_TOKEN }}
- name: Overwrite application.yml and logback.xml with submodule versions
run: |
mkdir -p src/main/resources
cp submodules/application.yml src/main/resources/application.yml
cp submodules/logback.xml src/main/resources/logback.xml
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-package: jdk
architecture: 'x64'
cache: 'gradle'
- name: Build with Gradle
run: |
cd ${{ github.workspace }}
chmod +x gradlew
./gradlew clean build
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
mask-password: 'true'
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION -f dockerfile_was .
docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION $ECR_REGISTRY/$ECR_REPOSITORY:latest
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION
docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$SEMANTIC_VERSION" >> $GITHUB_ENV
- name: Get latest ECS task definition
id: get-latest-task-def
run: |
TASK_DEF=$(aws ecs describe-services --cluster ${ECS_CLUSTER} --services ${ECS_SERVICE} --region ${AWS_REGION} --query "services[0].taskDefinition" --output text)
aws ecs describe-task-definition --task-definition $TASK_DEF --region ${AWS_REGION} --query "taskDefinition" --output json > task-definition.json
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ env.image }}
- name: Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true