[BG-321]: main 브랜치 cd 수정 (0.5h / 1h) #6
Workflow file for this run
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: 'CI/CD MAIN' | |
on: | |
push: | |
branches: | |
- 'main' | |
pull_request: | |
branches: | |
- 'develop' | |
env: | |
AWS_REGION: ap-northeast-2 | |
jobs: | |
build-api: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/[email protected] | |
- name: AWS IAM | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.ECR_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
- name: Cache Gradle packages | |
uses: actions/[email protected] | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
${{ runner.os }}-gradle- | |
- name: make application.yaml | |
run: | | |
cd ./api/src/main/resources/ | |
touch ./application.yaml | |
echo "${{ secrets.YAML_PROD_API }}" > ./application.yaml | |
shell: bash | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: Build with Gradle | |
run: ./gradlew :api:build -x test | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v2 | |
- name: Build, tag, and push docker image to Amazon ECR | |
env: | |
REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
REPOSITORY: backgu-repository | |
IMAGE_TAG: api | |
run: | | |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG -f Dockerfile-api . | |
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG | |
- name: Deploy Images with Docker compose | |
uses: appleboy/[email protected] | |
env: | |
APP: "backgu-api" | |
COMPOSE: "/home/ec2-user/compose/docker-compose-api.yaml" | |
with: | |
host: ${{secrets.EC2_PROD_BASTION}} | |
username: ec2-user | |
key: ${{secrets.EC2_PROD_PRIVATE_KEY}} | |
port: 22 | |
envs: APP, COMPOSE | |
script_stop: true | |
script: | | |
ssh prod1 | |
docker-compose -f $COMPOSE down | |
docker pull ${{secrets.API_IMAGE}} | |
docker-compose -f $COMPOSE up -d |