1- # .github/workflows/server_cd_develop.yml
21
32name : Release Server CD
43
54on :
65 push :
76 branches :
87 - ' main'
8+ - " setting/#542-oracle_cloud"
99 paths :
1010 - ' backend/**'
1111 - ' .github/workflows/**'
@@ -31,10 +31,12 @@ jobs:
3131 uses : gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0
3232
3333 - name : Cache Gradle dependencies
34- uses : actions/cache@v4 # Gradle 의존성 캐시 설정
34+ uses : actions/cache@v4
3535 with :
36- path : ~/.gradle/caches # Gradle 캐시 경로
37- key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} # Gradle 파일 해시값 기반 키
36+ path : |
37+ ~/.gradle/caches
38+ ~/.gradle/wrapper
39+ key : ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
3840 restore-keys : |
3941 ${{ runner.os }}-gradle-
4042
@@ -51,37 +53,26 @@ jobs:
5153 cd backend
5254 ./gradlew clean build -x test
5355
54- - id : ' auth'
55- uses : ' google-github-actions/auth@v2'
56+ # Docker 인증
57+ - name : Log in to Docker Hub
58+ uses : docker/login-action@v2
5659 with :
57- credentials_json : ${{ secrets.GCE_SA_KEY }}
60+ username : ${{ secrets.SERVER_DOCKER_USERNAME }}
61+ password : ${{ secrets.SERVER_DOCKER_PASSWORD }}
5862
59- # GCloud SDK 캐시 설정
60- - name : Cache Google Cloud SDK
61- uses : actions/cache@v4
62- with :
63- path : ~/.cache
64- key : gcloud-sdk-${{ runner.os }}
65- restore-keys : |
66- gcloud-sdk-
63+ - name : Set up Docker Buildx
64+ uses : docker/setup-buildx-action@v3
6765
68- # Google Cloud CLI 설정
69- - name : Set up Google Cloud SDK
70- uses : google-github-actions/setup-gcloud@v2
66+ - name : Build and Push ARM64 Docker Image
67+ uses : docker/build-push-action@v5
7168 with :
72- project_id : ${{ secrets.GCE_PROJECT }}
73-
74- # Docker 인증
75- - name : Authenticate Docker to Google Cloud Container Registry (GCR)
76- run : |
77- gcloud auth configure-docker asia-northeast3-docker.pkg.dev
78-
79- # Docker 이미지 빌드 및 GCR 업로드
80- - name : Build and Push Docker Image
81- run : |
82- cd backend
83- docker build -t ${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ github.sha }} -t ${{ secrets.DOCKER_IMAGE_DEV }}:latest .
84- docker push -a ${{ secrets.DOCKER_IMAGE_RELEASE }}
69+ context : ./backend
70+ file : ./backend/Dockerfile
71+ platforms : linux/arm64,linux/amd64
72+ push : true
73+ tags : |
74+ ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
75+ ${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ github.sha }}
8576
8677 deploy :
8778 name : Deploy
@@ -93,33 +84,27 @@ jobs:
9384
9485 steps :
9586
96- # gcloud-setup workflow 호출
97- - id : ' auth'
98- uses : ' google-github-actions/auth@v2'
87+ - name : Log in to Docker Hub
88+ uses : docker/login-action@v2
9989 with :
100- credentials_json : ${{ secrets.GCE_SA_KEY }}
101-
102- # Google Cloud CLI 설정
103- - name : Set up Google Cloud SDK
104- uses : google-github-actions/setup-gcloud@v2
105- with :
106- project_id : ${{ secrets.GCE_PROJECT }}
90+ username : ${{ secrets.SERVER_DOCKER_USERNAME }}
91+ password : ${{ secrets.SERVER_DOCKER_PASSWORD }}
10792
93+ # oracle ssh 접속 후 배포
10894 - name : Update Container on VM
109- run : |
110- gcloud compute ssh ${{ secrets.GCE_INSTANCE_RELEASE }} --zone=${{ secrets.GCP_REGION }} --command="
111- gcloud auth configure-docker asia-northeast3-docker.pkg.dev
112- gcloud auth activate-service-account --key-file=/home/${{ secrets.GCE_INSTANCE_USER }}/gce_sa_key.json
113-
114- sudo usermod -aG docker $USER
115- newgrp docker
116-
117- docker pull ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
118-
119- export USERNAME=${{ secrets.GCE_INSTANCE_USER }} # docker compose 파일에서 사용할 변수명 설정
120- export DOCKER_APP_IMAGE=${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
121- sudo chmod +x /home/${{ secrets.GCE_INSTANCE_USER }}/deploy.sh # 실행 권한 부여
122- sudo -E /home/${{ secrets.GCE_INSTANCE_USER }}/deploy.sh # su권한으로 환경 변수 유지 및 실행
123-
124- docker image prune -af
125- docker ps -a"
95+ uses : appleboy/ssh-action@master
96+ with :
97+ host : ${{ secrets.ORACLE_INSTANCE_RELEASE_IP }}
98+ username : ${{ secrets.ORACLE_INSTANCE_USER }}
99+ key : ${{ secrets.ORACLE_INSTANCE_RELEASE_PRIVATE_KEY }}
100+ port : ${{ secrets.ORACLE_INSTANCE_RELEASE_PORT }}
101+ script : |
102+ docker pull ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
103+
104+ echo $(whoami)
105+ export USERNAME=${{ secrets.ORACLE_INSTANCE_USER }}
106+ export DOCKER_APP_IMAGE=${{ secrets.DOCKER_IMAGE_RELEASE }}:latest
107+ sudo chmod +x /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh
108+ sudo -E /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh
109+
110+ docker image prune -af
0 commit comments