π API μλ² λͺ¨λν°λ§ μλΉμ€ Centry μ μ© #19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy dev API to Amazon ECS | |
on: | |
push: | |
branches: [ "dev" ] | |
permissions: | |
contents: read | |
env: | |
AWS_REGION: ap-northeast-2 | |
SERVER_PORT: 8080 | |
jobs: | |
job: | |
name: Deploy dev API | |
runs-on: ubuntu-latest | |
environment: dev | |
steps: | |
- name: μ²΄ν¬ μμ | |
uses: actions/checkout@v3 | |
- name: JDK 17 μ€μΉ | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
- name: AWS credentials μ€μ | |
uses: aws-actions/configure-aws-credentials@v1 | |
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: application.yml μ€λ²λΌμ΄λ | |
uses: microsoft/variable-substitution@v1 | |
with: | |
files: ./src/main/resources/application.yml | |
env: | |
server.port: ${{ env.SERVER_PORT }} | |
cors.service-origin: ${{ secrets.SERVICE_ORIGIN }} | |
sentry.dsn: ${{ secrets.SENTRY_DSN }} | |
spring.datasource.driver-class-name: ${{ secrets.DRIVER_CLASS_NAME }} | |
spring.datasource.username: ${{ secrets.MYSQL_USERNAME }} | |
spring.datasource.password: ${{ secrets.MYSQL_PASSWORD }} | |
spring.datasource.url: ${{ secrets.MYSQL_URL }} | |
spring.data.redis.host: ${{ secrets.REDIS_HOST }} | |
spring.data.redis.port: ${{ secrets.REDIS_PORT }} | |
spring.cloud.aws.credentials.accessKey: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
spring.cloud.aws.credentials.secretKey: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
spring.cloud.aws.region.static: ${{ env.AWS_REGION }} | |
spring.cloud.aws.s3.bucket: ${{ secrets.AWS_S3_IMAGE_BUCKET }} | |
spring.cloud.aws.s3.endpoint: ${{ secrets.AWS_S3_IMAGE_ENDPOINT }} | |
jwt.issuer: ${{ secrets.TOKEN_ISSUER }} | |
jwt.base64-secret: ${{ secrets.TOKEN_SECRET }} | |
jwt.token-validity-in-seconds: ${{ secrets.TOKEN_EXPIRATION }} | |
- name: Redis μ€ν | |
uses: supercharge/[email protected] | |
with: | |
redis-version: 7.2.4-alpine | |
redis-port: 6379 | |
- name: νλ‘μ νΈ λΉλ | |
uses: gradle/[email protected] | |
with: | |
arguments: clean build | |
- name: Amazon ECR λ‘κ·ΈμΈ | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: docker μ΄λ―Έμ§ μ λ‘λ | |
id: build-image | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
IMAGE_TAG: ${{ github.sha }} | |
PROFILE: ${{ vars.SPRING_ACTIVE_PROFILE }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG --build-arg PROFILE=$PROFILE . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | |
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | |
- name: Amazon ECS task definition μ΄λ―Έμ§ μ€μ | |
id: task-def | |
uses: aws-actions/amazon-ecs-render-task-definition@v1 | |
with: | |
task-definition: ${{ vars.ECS_TASK_DEFINITION }} | |
container-name: ${{ vars.CONTAINER_NAME }} | |
image: ${{ steps.build-image.outputs.image }} | |
- name: Amazon ECS task definition λ°°ν¬ | |
uses: aws-actions/amazon-ecs-deploy-task-definition@v1 | |
with: | |
task-definition: ${{ steps.task-def.outputs.task-definition }} | |
service: ${{ vars.ECS_SERVICE }} | |
cluster: ${{ vars.ECS_CLUSTER }} | |
wait-for-service-stability: true |