Skip to content

운영계 배포

운영계 배포 #22

Workflow file for this run

name: "운영계 배포"
on:
workflow_dispatch:
inputs:
version:
description: "Release Version"
required: true
type: string
default: 'v0.0.7'
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@v4
- name: Version
id: version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "::set-output name=version::$VERSION"
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
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@v2
- name: Set up JDK 17
uses: actions/setup-java@v4
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: Test
run: ./gradlew test
- 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 }}
PINPOINT_COLLECTOR_IP: ${{ secrets.PINPOINT_COLLECTOR_IP_PROD }}
run: |
docker build -t $DOCKER_REGISTRY/$DOCKER_REPOSITORY:$IMAGE_TAG --build-arg PROFILE=PROD --build-arg COLLECTOR_IP=${PINPOINT_COLLECTOR_IP} -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@v2
with:
task-definition: ${{ steps.render-api-container.outputs.task-definition }}
cluster: three-dollar-community-ecs
service: community-api-rpd
wait-for-service-stability: true