배포 1.1.6 #69
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: crews backend deploy | |
on: | |
push: | |
branches: [ "main" ] | |
permissions: | |
contents: read | |
jobs: | |
test: | |
uses: ./.github/workflows/ci.yml | |
secrets: inherit | |
build: | |
needs: test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.ACTION_TOKEN }} | |
submodules: true | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Cache Gradle dependencies | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.gradle/caches | |
~/.gradle/wrapper | |
key: gradle-${{ runner.os }}-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
restore-keys: | | |
gradle-${{ runner.os }}- | |
- name: Build with Gradle | |
run: ./gradlew build -x test | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker Image And Push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.DOCKER_PROD_SERVER_IMAGE_NAME }} | |
platforms: | | |
linux/amd64 | |
linux/arm64 | |
- name: Copy docker-compose.yml to server | |
uses: appleboy/[email protected] | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
source: "./src/main/resources/config/docker-compose.yml" | |
target: "/home/ubuntu" | |
strip_components: 5 | |
deploy: | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- name: deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.HOST }} | |
username: ubuntu | |
key: ${{ secrets.KEY }} | |
script: | | |
cd /home/ubuntu | |
sudo chmod 666 /var/run/docker.sock | |
sudo chmod +x /usr/local/bin/docker-compose | |
docker pull ${{ secrets.DOCKER_PROD_SERVER_IMAGE_NAME }} | |
docker rm -f crews-server | |
docker-compose up crews-server -d | |
docker image prune -f | |
docker volume prune -f |