Skip to content

fix: main.yml

fix: main.yml #7

Workflow file for this run

name: CI/CD using github actions & docker
on:
push:
branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트
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: 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 & push to prod
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2 .
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2
# - name: Install Docker
# run: |
# sudo apt-get update
# sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# sudo apt-get update
# sudo apt-get install docker-ce
- name: Deploy to prod
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
port: ${{ secrets.PORT }} #ssh port (22)
envs: GITHUB_SHA
script: |
docker stop sopo_v2
docker rm sopo_v2
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker run -d -p 8080:8080 --name welspy ${{ secrets.DOCKER_USERNAME }}/sopo_v2