Skip to content

Merge pull request #9 from Sam3Star/gayeong #18

Merge pull request #9 from Sam3Star/gayeong

Merge pull request #9 from Sam3Star/gayeong #18

Workflow file for this run

name: CI/CD using github actions & docker
on:
push:
branches: [ "main" ]
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: Set yml file
uses: microsoft/variable-substitution@v1
with:
files: src/main/resources/application.yml
env:
spring.datasource.url: ${{ secrets.DB_URL }}
spring.datasource.username: ${{ secrets.DB_USER }}
spring.datasource.password: ${{ secrets.DB_PASSWORD }}
- name: set chmod
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/clock .
docker push ${{ secrets.DOCKER_USERNAME }}/clock
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOST_PROD }}
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }}
port: ${{ secrets.PORT }}
envs: GITHUB_SHA
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker stop clock
docker rm clock
docker rmi ${{ secrets.DOCKER_USERNAME }}/clock:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/clock:latest
docker run -d -p 80:8080 --name clock ${{ secrets.DOCKER_USERNAME }}/clock:latest