Skip to content

Merge pull request #143 from c0smosaur/dev #132

Merge pull request #143 from c0smosaur/dev

Merge pull request #143 from c0smosaur/dev #132

Workflow file for this run

name: DockerCompose With Gradle
on:
push:
branches:
- main
- dev
permissions: write-all
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
- name: Add permission
run: chmod +x gradlew
- name: Clean before Build
run: ./gradlew clean
- name: Inject Secret values into application-test.yml
run: |
sed -i "s|# MYSQL_URL|url: '${{ secrets.MYSQL_URL }}'|" src/main/resources/application-prod.yml
sed -i "s|# MYSQL_USERNAME|username: '${{ secrets.MYSQL_USERNAME }}'|" src/main/resources/application-prod.yml
sed -i "s|# MYSQL_PASSWORD|password: '${{ secrets.MYSQL_PASSWORD }}'|" src/main/resources/application-prod.yml
sed -i "s|# REDIS_HOST|host: '${{ secrets.REDIS_HOST }}'|" src/main/resources/application-prod.yml
sed -i "s|# REDIS_PORT|port: '${{ secrets.REDIS_PORT }}'|" src/main/resources/application-prod.yml
sed -i "s|# REDIS_PASSWORD|password: '${{ secrets.REDIS_PASSWORD }}'|" src/main/resources/application-prod.yml
sed -i "s|# SMTP_EMAIL|username: '${{ secrets.SMTP_EMAIL }}'|" src/main/resources/application-prod.yml
sed -i "s|# SMTP_PASSWORD|password: '${{ secrets.SMTP_PASSWORD }}'|" src/main/resources/application-prod.yml
sed -i "s|# SMTP_HOST|host: '${{ secrets.SMTP_HOST }}'|" src/main/resources/application-prod.yml
sed -i "s|# SMTP_PORT|port: '${{ secrets.SMTP_PORT }}'|" src/main/resources/application-prod.yml
sed -i "s|# S3_BUCKET_NAME|bucket: '${{ secrets.S3_BUCKET_NAME }}'|" src/main/resources/application-prod.yml
sed -i "s|# S3_ACCESS_KEY|access-key: '${{ secrets.S3_ACCESS_KEY }}'|" src/main/resources/application-prod.yml
sed -i "s|# S3_SECRET_KEY|secret-key: '${{ secrets.S3_SECRET_KEY }}'|" src/main/resources/application-prod.yml
sed -i "s|# S3_BUCKET_REGION|static: '${{ secrets.S3_BUCKET_REGION }}'|" src/main/resources/application-prod.yml
sed -i "s|# JWT_SECRET_KEY|secret-key: '${{ secrets.JWT_SECRET_KEY }}'|" src/main/resources/application-prod.yml
shell: bash
env:
JAVA_HOME: /opt/hostedtoolcache/Java_Corretto_jdk/17.0.11-9.1/x64
JAVA_HOME_17_X64: /opt/hostedtoolcache/Java_Corretto_jdk/17.0.11-9.1/x64
- name: Docker Build & Push
run: |
docker login -u ${{ secrets.DOCKER_ID }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build --platform linux/amd64 -t ${{ secrets.DOCKER_REPO }} .
docker push ${{ secrets.DOCKER_REPO }}
- name: SSH Connection & Deploy
uses: appleboy/ssh-action@master
env:
APP: "docker-project"
COMPOSE: "/home/ubuntu/compose/docker-compose.yml"
with:
username: ubuntu
host: ${{ secrets.EC2_HOST }}
key: ${{ secrets.EC2_PRIVATE_KEY }}
envs: APP, COMPOSE
script_stop: true
script: |
# sudo docker-compose -f $COMPOSE down
# sudo docker pull ${{ secrets.DOCKER_REPO }}
# sudo docker-compose -f $COMPOSE up -d
sudo docker-compose -f $COMPOSE pull spring-boot-app
sudo docker-compose -f $COMPOSE up -d spring-boot-app
timeout: 30s
command_timeout: 10m
debug: true