Skip to content

Merge pull request #314 from HyunJunSon/tuning/api #123

Merge pull request #314 from HyunJunSon/tuning/api

Merge pull request #314 from HyunJunSon/tuning/api #123

Workflow file for this run

name: CI and CD in WashPedia Project
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: "17"
distribution: "temurin"
- name: Replace SQL Queries
run: |
dir_path="./module-domain/src/main/resources/db/migration"
old_text="changeRequired"
new_text="${{ secrets.PUBLIC_KEY }}"
find "$dir_path" -type f -name "*.sql" -exec sed -i "s|$old_text|$new_text|g" {} +
- name: Set application yml file (api)
uses: microsoft/variable-substitution@v1
with:
files: ./module-api/src/main/resources/application.yml
env:
spring.profiles.active: "dev"
- name: Set application yml file (batch)
uses: microsoft/variable-substitution@v1
with:
files: ./module-batch/src/main/resources/application.yml
env:
spring.profiles.active: "dev"
- name: Set application-dev yml file (api)
uses: microsoft/variable-substitution@v1
with:
files: ./module-api/src/main/resources/application-dev.yml
env:
spring.datasource.url: ${{ secrets.DB_URL }}
spring.datasource.username: ${{ secrets.DB_USER }}
spring.datasource.password: ${{ secrets.DB_PW }}
spring.mail.username: ${{ secrets.SMTP_GOOGLE_EMAIL }}
spring.mail.password: ${{ secrets.SMTP_PASSWORD }}
spring.data.redis.host: ${{ secrets.REDIS_DEV_HOST }}
spring.data.redis.password: ${{ secrets.REDIS_DEV_PASSWORD }}
constants.host-url: ${{ secrets.DEV_HOST_URL }}
aws.credentials.access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws.credentials.secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws.s3.bucket.name: ${{ secrets.AWS_S3_BUCKET_NAME }}
aws.s3.bucket.url: ${{ secrets.AWS_S3_BUCKET_URL }}
- name: Set application-dev yml file (batch)
uses: microsoft/variable-substitution@v1
with:
files: ./module-batch/src/main/resources/application-dev.yml
env:
spring.datasource.url: ${{ secrets.VULTR_DB_URL }}
spring.datasource.username: ${{ secrets.DB_USER }}
spring.datasource.password: ${{ secrets.DB_PW }}
external.ecolife-api.path: ${{ secrets.ECOLIFE_PATH }}
external.ecolife-api.service-key: ${{ secrets.ECOLIFE_KEY }}
- name: Grant execute permission And Build with Gradle (api)
working-directory: ./module-api
run: |
chmod +x ./gradlew
./gradlew bootJar
- name: Grant execute permission And Build with Gradle (batch)
working-directory: ./module-batch
run: |
chmod +x ./gradlew
./gradlew bootJar
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.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: Build, tag, and push docker image to Amazon ECR (api)
working-directory: ./module-api
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: dev-washfit-api
IMAGE_TAG: latest
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Build, tag, and push docker image to Amazon ECR (batch)
working-directory: ./module-batch
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
REPOSITORY: dev-washfit-batch
IMAGE_TAG: latest
run: |
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Application Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.VULTR_IP }}
username: ${{ secrets.VULTR_USERNAME }}
password: ${{ secrets.VULTR_PW }}
script: |
# Install Docker and Docker Compose
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install -y docker-ce docker-ce-cli containerd.io
systemctl start docker
systemctl enable docker
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
# Docker Compose
mkdir -p deploy
cd deploy
echo "${{ secrets.DB_INIT_SQL }}" > init.sql
echo "${{ secrets.DEV_REDIS_CONF }}" > ./redis/redis.conf
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin ${{ steps.login-ecr.outputs.registry }}
docker image prune -af
docker-compose pull
docker-compose down
docker-compose up -d