Skip to content

Merge pull request #11 ✨ CI/CD Test 2차 #11

Merge pull request #11 ✨ CI/CD Test 2차

Merge pull request #11 ✨ CI/CD Test 2차 #11

Workflow file for this run

name: Web Application Dev Server CI/CD
on:
push:
branches: [ "develop" ]
pull_request_target:
types: [labeled, closed]
jobs:
# safe tag에 대한 gradlew test && merged에 대한 gradlew build/deploy
CI:
if: contains(github.event.pull_request.labels.*.name, 'safe')
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
# repo settings에서 설정한 secrets 값을 사용한다.
ref: ${{ github.event.pull_request.head.sha }}
token: ${{ secrets.ACCESS_TOKEN }}
submodules: true
### runner application java 설정
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
### gradlew 실행 권한 부여
- name: Grant execute permisstion for gradlew
run: chmod +x gradlew
### project test
- name: Test
if: contains(github.event.pull_request.labels.*.name, 'safe')
run: ./gradlew clean test -Pprofile=test
### project build
- name: Build with Gradle
if: github.event.pull_request.merged == true
run: ./gradlew clean build
### Docker Image Build and Push
- name: Login to Docker Hub
if: github.event.pull_request.merged == true
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Set up Docker Buildx
if: github.event.pull_request.merged == true
uses: docker/setup-buildx-action@v2
- name: Build and push
if: github.event.pull_request.merged == true
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
# closed에 대한 server deploy
CD:
if: github.event.pull_request.merged == true
needs: [CI]
runs-on: ubuntu-20.04
steps:
### SSH Connect and Docker Image Pull and Container Run
- name: Docker Image Pull and Container Run
uses: appleboy/[email protected]
with:
host: ${{ secrets.DEV_SSH_HOST }}
username: ${{ secrets.DEV_SSH_USERNAME }}
password: ${{ secrets.DEV_SSH_PASSWORD }}
key: ${{ secrets.DEV_SSH_KEY }}
port: ${{ secrets.DEV_SSH_PORT }}
script: |
docker stop emodiary-was
docker rm emodiary-was
docker image rm ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}
docker run -d -v /root/emodiary/resources:/app/resources --net emodiary-bridge --ip 172.30.0.3 -p 8090:8080 --name emodiary-was ${{ secrets.DOCKERHUB_USERNAME }}/${{ secrets.DOCKERHUB_REPONAME }}