-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd7609
commit 68bceab
Showing
1 changed file
with
36 additions
and
30 deletions.
There are no files selected for viewing
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
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 |