Skip to content

Merge pull request #26 from aws-cloud-clubs/feature/issue-25 #21

Merge pull request #26 from aws-cloud-clubs/feature/issue-25

Merge pull request #26 from aws-cloud-clubs/feature/issue-25 #21

Workflow file for this run

# github repository Actions 페이지에 나타낼 이름
name: ACC-hotsix CI/CD
# event trigger
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-22.04
steps:
## jdk setting
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
## gradle caching
- name: Gradle Caching
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Grant execute permission for gradlew
run: chmod +x gradlew
## create application-prod.yml
- name: create application.yml
run: |
cd ./src/main
cd ./resources
touch ./application.yml
ls *
echo "${{ secrets.APPLICATION_YML }}" > ./application.yml
- name: Build with Gradle
run: ./gradlew build -x test
## deploy to production
- name: Configure AWS IAM credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: ap-northeast-2
- name: Login to ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
## docker build
- name: build docker file and setting deploy files
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: acc6-ecr
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
mkdir scripts
touch scripts/deploy.sh
echo "aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_REGISTRY" >> scripts/deploy.sh
echo "docker pull $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
echo "docker run -p 8080:8080 -e PROFILE=dev -d --restart always --name csbroker-api $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> scripts/deploy.sh
- name: Upload to S3
env:
IMAGE_TAG: ${{ github.sha }}
run: |
zip -r deploy-$IMAGE_TAG.zip ./scripts appspec.yml
aws s3 cp --region ap-northeast-2 --acl private ./deploy-$IMAGE_TAG.zip s3://acc6-s3-dev-an2
- name: Start CodeDeploy Agent
env:
IMAGE_TAG: ${{ github.sha }}
run: >
aws deploy create-deployment --application-name hotsix
--deployment-config-name CodeDeployDefault.AllAtOnce
--deployment-group-name deploy-group
--s3-location bucket=acc6-s3-dev-an2,bundleType=zip,key=deploy-$IMAGE_TAG.zip