-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 빌드 작업과 배포 작업을 분리 - 기존 workflow 빌드, 배포 업무 개선
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
name: PhotosMap CI/CD Workflow | ||
|
||
on: | ||
push: | ||
branches: [ "develop" ] | ||
pull_request: | ||
branches: [ "develop" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Create application-base-addi.yml | ||
run: echo "${{ secrets.BASE_ADDI }}" > ./src/main/resources/application-base-addi.yml | ||
|
||
- name: Create docker-compose-prod.yml | ||
run: echo "${{ secrets.DOCKER_COMPOSE_PROD }}" > ./docker-compose-prod.yml | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v2 | ||
with: | ||
distribution: 'adopt' | ||
java-version: '17' | ||
|
||
- name: Grant execute permission for gradlew | ||
run: chmod +x ./gradlew | ||
|
||
- name: Build with Gradle | ||
run: ./gradlew bootJar | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_PASSWORD }} | ||
|
||
- name: Build Docker image | ||
run: docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/photosmap:latest --build-arg PROFILES=prod . | ||
|
||
- name: Push Docker image to Docker Hub | ||
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/photosmap:latest | ||
|
||
- name: Upload artifacts | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: build-artifacts | ||
path: | | ||
./src/main/resources/application-base-addi.yml | ||
./docker-compose-prod.yml | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: build | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up SSH | ||
uses: webfactory/ssh-agent@v0.5.3 | ||
with: | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- name: Download artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: build-artifacts | ||
path: ./ | ||
|
||
- name: Copy files to EC2 | ||
run: | | ||
scp -P ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ./docker-compose-prod.yml ${{ secrets.SSH_USER }}@${{ secrets.EC2_HOST }}:${{ secrets.EC2_PATH }}/ | ||
scp -P ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ./src/main/resources/application-base-addi.yml ${{ secrets.SSH_USER }}@${{ secrets.EC2_HOST }}:${{ secrets.EC2_PATH }}/ | ||
- name: Docker login on EC2 | ||
run: | | ||
ssh -t -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.EC2_HOST }} "docker login -u ${{ secrets.DOCKERHUB_USERNAME }} -p ${{ secrets.DOCKERHUB_PASSWORD }}" | ||
- name: Pull and deploy Docker image on EC2 | ||
run: | | ||
ssh -t -p ${{ secrets.SSH_PORT }} -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.EC2_HOST }} " | ||
docker pull ${{ secrets.DOCKERHUB_USERNAME }}/photosmap:latest && | ||
docker-compose -f ${{ secrets.EC2_PATH }}/docker-compose-prod.yml down && | ||
docker-compose -f ${{ secrets.EC2_PATH }}/docker-compose-prod.yml up -d | ||
" |