Skip to content

운영계 배포

운영계 배포 #1

Workflow file for this run

name: "운영계 배포"
on:
workflow_dispatch:
inputs:
version:
description: "Release Version"
required: true
type: string
jobs:
validate-version:
name: 배포 태그 버전 검증
runs-on: ubuntu-latest
steps:
- name: Check assigned tag
uses: actions/github-script@v7
if: ${{GITHUB.REF_TYPE != 'tag'}}
with:
script: core.setFailed('You should deploy with tag (not branch !)')
- name: validate semantic versioning
run: |
if [[ ! "${{ github.ref_name }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo 'version "${{ github.ref_name }}" not in semantic versioning format ex) v0.0.1'
exit 1
fi
deploy:
name: community-deploy
runs-on: ubuntu-latest
environment: "prod"
needs:
- validate-version
steps:
- name: checkout@v2
uses: actions/checkout@v2
- name: Version
id: version
run: |
VERSION=${VERSIONING#v}-${{ github.run_id }}
echo "::set-output name=version::$VERSION"
env:
VERSIONING: ${{ github.event.inputs.version }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Set up JDK 17
uses: actions/setup-java@v1
with:
java-version: 17
distribution: temurin
cache: gradle
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew
- name: Setup Docker compose
run: docker-compose -f "docker/test/docker-compose.yml" up -d
- name: Build with Gradle
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
with:
arguments: build
- name: Build Community API Image
id: build
env:
DOCKER_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
DOCKER_REPOSITORY: 3dollar-community-api
IMAGE_TAG: ${{ steps.version.outputs.version }}
run: |
docker build -t $DOCKER_REGISTRY/$DOCKER_REPOSITORY:$IMAGE_TAG -f ./threedollar-application/Dockerfile .
docker tag $DOCKER_REGISTRY/$DOCKER_REPOSITORY:$IMAGE_TAG $DOCKER_REGISTRY/$DOCKER_REPOSITORY:latest
docker push $DOCKER_REGISTRY/$DOCKER_REPOSITORY:$IMAGE_TAG
docker push $DOCKER_REGISTRY/$DOCKER_REPOSITORY:latest
echo "::set-output name=image::$DOCKER_REGISTRY/$DOCKER_REPOSITORY:$IMAGE_TAG"
echo "🐇 Build Image >> $DOCKER_REPOSITORY$IMAGE_TAG"
- name: Download task definition
id: download-task-definition
run: |
aws ecs describe-task-definition --task-definition threedollar-community-api-prod --query taskDefinition > task-definition-community-prod.json
echo "task-definition=$GITHUB_WORKSPACE/task-definition-community-prod.json" >> $GITHUB_OUTPUT
- name: Update Amazon ECS task definition
id: render-api-container
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ steps.download-task-definition.outputs.task-definition }}
container-name: threedollar-community-api-prod
image: ${{ steps.build.outputs.image }}
- name: Deploy to Amazon ECS service
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-api-container.outputs.task-definition }}
cluster: three-dollar-community-ecs
service: community-api-rpd
wait-for-service-stability: true