[Feat] update dev server deploy script #468
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: Deploy to Test Instance | |
on: | |
workflow_dispatch: | |
inputs: | |
logLevel: | |
description: 'Log level' | |
required: true | |
default: 'warning' | |
type: choice | |
options: | |
- info | |
- warning | |
- debug | |
repository_dispatch: | |
types: [deploy-to-test-event] | |
push: | |
branches: [ develop ] | |
pull_request: | |
types: [ edited ] | |
env: | |
SPRING_PROFILES_ACTIVE: dev | |
ECR_APP_NAME: ${{ secrets.ECR_APP_NAME }}-dev | |
ECR_REPO: ${{ secrets.ECR_HOST }}/${{ secrets.ECR_APP_NAME }}-dev | |
ECR_HOST: ${{ secrets.ECR_HOST }} | |
jobs: | |
build: | |
name: CD Pipeline | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 1.17 | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'corretto' | |
java-version: '17' | |
- name: 'Check Java Version' | |
run: | | |
java --version | |
echo 'ecr repo is $ECR_REPO' | |
- name: 'Configure AWS credentials' | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID__TEAM_PLAYGROUND }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY__TEAM_PLAYGROUND }} | |
aws-region: ap-northeast-2 | |
- name: 'Get application.yml from AWS S3' | |
run: | | |
aws s3 cp \ | |
--region ap-northeast-2 \ | |
s3://sopt-makers-internal/dev/deploy/application-dev.yml src/main/resources/application.yml | |
- name: 'Get key from AWS S3' | |
run: | | |
aws s3 cp \ | |
--region ap-northeast-2 \ | |
s3://sopt-makers-internal/dev/deploy/${{ secrets.APPLE_KEY }} src/main/resources/static/${{ secrets.APPLE_KEY }} | |
- name: 'Build with Gradle' | |
run: | | |
chmod +x ./gradlew | |
./gradlew clean build -x test | |
shell: bash | |
- name: 'Configure Docker Build Environment' | |
uses: docker/[email protected] | |
- name: 'Login to ECR' | |
run: | | |
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin $ECR_HOST | |
- name: 'Docker Image Build & Push' | |
run: | | |
docker buildx build --platform linux/arm64 -f Dockerfile -t $ECR_REPO . | |
docker push $ECR_REPO | |
- name: 'Send docker-compose.yml to EC2 Instance' | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.DEV_RELEASE_SERVER_IP }} | |
username: ${{ secrets.RELEASE_SERVER_USER }} | |
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }} | |
source: "./docker-compose.yml" | |
target: "/home/ec2-user/" | |
- name: 'Send deploy script to EC2 Instance' | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.DEV_RELEASE_SERVER_IP }} | |
username: ${{ secrets.RELEASE_SERVER_USER }} | |
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }} | |
source: "./scripts/deploy.sh" | |
target: "/home/ec2-user/app/" | |
- name: 'Get current time' | |
uses: 1466587594/get-current-time@v2 | |
id: current-time | |
with: | |
format: YYYY-MM-DDTHH-mm-ss | |
utcOffset: "+09:00" | |
- name: 'Docker Container Run' | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.DEV_RELEASE_SERVER_IP }} | |
username: ${{ secrets.RELEASE_SERVER_USER }} | |
key: ${{ secrets.DEV_RELEASE_SERVER_KEY }} | |
script: | | |
cd ~ | |
sudo docker pull ${{ secrets.ECR_REPO }} | |
sudo chmod +x ./deploy.sh | |
cp ./app/scripts/deploy,sh | |
./deploy.sh | |
docker image prune -f |