Merge pull request #334 from ASAP-as-soon-as-possible/develop #33
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
name: ASAP-Server CD | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
name: Code deployment | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: make application.yml 파일 생성 | |
run: | | |
## create application.yml | |
cd ./src/main/resources | |
# application.yml 파일 생성 | |
touch ./application.yml | |
# GitHub-Actions 에서 설정한 값을 application.yml 파일에 쓰기 | |
echo "${{ secrets.DOCKER_YAML }}" >> ./application.yml | |
# application.yml 파일 확인 | |
cat ./application.yml | |
shell: bash | |
- name: Build with Gradle | |
run: | | |
chmod +x gradlew | |
./gradlew build -x test | |
- name: docker build 가능하도록 환경 설정 | |
uses: docker/[email protected] | |
- name: docker hub에로그인 | |
uses: docker/[email protected] | |
with: | |
username: ${{ secrets.DOCKERHUB_LOGIN_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_LOGIN_ACCESSTOKEN }} | |
- name: JAR file 로 부터 서버 버전 추출 | |
id: server_version | |
run: | | |
jar_file=$(ls build/libs/server-*.jar | head -n 1) | |
version=$(echo $jar_file | grep -oP 'server-\K[^\-]+(?=\.jar)') | |
echo "Version: $version" | |
echo "::set-output name=version::$version" | |
- name: docker image 빌드 및 푸시 | |
run: | | |
docker build --platform linux/amd64 -t ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} . | |
docker tag ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${{ steps.server_version.outputs.version }} | |
docker push ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }}:${{ steps.server_version.outputs.version }} | |
docker push ${{ secrets.DOCKERHUB_LOGIN_USERNAME }}/${{ secrets.DOCKERHUB_IMAGE_NAME }} | |
- name: 도커 컨테이너 실행 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.RELEASE_SERVER_IP }} | |
username: ${{ secrets.RELEASE_SERVER_USER }} | |
key: ${{ secrets.RELEASE_SERVER_KEY }} | |
script: | | |
cd ~ | |
sudo ./deploy.sh |