Merge pull request #3 from Dev-Tinos/improve/정우진 #45
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: Build Test | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
publish: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: build with gradle | |
run: | | |
cd ./game-server | |
./gradlew build | |
- name: Docker Login | |
uses: docker/login-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Docker Build and Push | |
uses: docker/build-push-action@v2 | |
with: | |
context: ./game-server | |
file: game-server/Dockerfile | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }} | |
- name: Publish in EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.SSH_PRIVATE_KEY }} | |
script: | | |
sudo docker pull ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest | |
sudo docker stop ${{ secrets.REPOSITORY_NAME }} || true | |
sudo docker rm ${{ secrets.REPOSITORY_NAME }} || true | |
sudo docker run -d --name ${{ secrets.REPOSITORY_NAME }} -p 8000:8000 ${{ secrets.DOCKER_USERNAME }}/${{ secrets.REPOSITORY_NAME }}:latest |