Skip to content

Commit

Permalink
fix: init
Browse files Browse the repository at this point in the history
  • Loading branch information
alexipharmical committed Jun 10, 2024
1 parent bdd7609 commit 68bceab
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
name: CI/CD using github actions & docker
name: CD with Gradle

on:
push:
branches: [ "main" ] # 해당 branch에 푸쉬 발생 시 업데이트
branches: [ "main" ]

permissions:
contents: read

jobs:
CI-CD:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
distribution: "temurin"

- name: set chmod
run: chmod +x ./gradlew
- name: Make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
shell: bash

- name: Build with Gradle
run: ./gradlew jar
run: |
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to prod
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1 .
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1
# - 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
docker build -t sopo_v2 . # Dockerfile 경로 수정
docker tag sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest
- name: Deploy with SSH
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@master
id: deploy-prod

with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
port: ${{ secrets.PORT }} #ssh port (22)
envs: GITHUB_SHA
key: ${{ secrets.PRIVATE_KEY }} # pem 키
# 도커 작업
script: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker stop sopo_v2
docker rm sopo_v2
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1
docker run -d -p 8080:8080 --name welspy ${{ secrets.DOCKER_USERNAME }}/sopo_v2:0.0.1\
docker network disconnect redis-network sopo_v2
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest
docker run -d -p 80:8080 --name sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2:latest
docker network connect redis-network sopo_v2

0 comments on commit 68bceab

Please sign in to comment.