Merge pull request #8 from AppJam-27th/gayeong #24
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: CI/CD using github actions & docker | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
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: '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_USERNAME }} | |
spring.datasource.password: ${{ secrets.DB_PASSWORD }} | |
- name: Grant execute permission for gradlew | |
run: chmod +x gradlew | |
- name: set chmod | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew build | |
- name: List build/libs contents | |
run: ls -la build/libs | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t appjam . | |
docker build -t ${{ secrets.DOCKER_USERNAME }}/appjam . | |
docker push ${{ secrets.DOCKER_USERNAME }}/appjam:latest | |
- 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: | | |
script: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker stop appjam | |
docker rm appjam | |
docker rmi ${{ secrets.DOCKER_USERNAME }}/appjam:latest | |
docker pull ${{ secrets.DOCKER_USERNAME }}/appjam:latest | |
docker run -d -p 80:8080 --name appjam ${{ secrets.DOCKER_USERNAME }}/appjam:latest |