chore: main.yml #56
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" ] | |
pull_request: | |
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: make application.yml | |
run: | | |
cd ./src/main/resources | |
touch ./application.yml | |
echo "${{ secrets.APPLICATION }}" > ./application.yml | |
- name: set chmod | |
run: chmod +x ./gradlew | |
- name: Build with Gradle | |
run: ./gradlew bootJar | |
- name: Docker build | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker build -t sopo . # Dockerfile 경로 수정 | |
docker tag sopo ${{ secrets.DOCKER_USERNAME }}/sopo:latest | |
docker push ${{ secrets.DOCKER_USERNAME }}/sopo:latest | |
- name: Deploy with SSH | |
if: github.ref == 'refs/heads/main' | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS | |
username: ubuntu | |
key: ${{ secrets.PRIVATE_KEY }} # pem 키 | |
port: ${{ secrets.PORT }} # ssh port (22) | |
envs: GITHUB_SHA | |
script: | | |
script: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker stop sopo | |
docker rm sopo | |
docker network disconnect redis-network sopo | |
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo:latest | |
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo:latest | |
docker run -d -p 80:8080 --name sopo ${{ secrets.DOCKER_USERNAME }}/sopo:latest | |
docker network connect redis-network sopo |