Merge pull request #70 from Kookmin-Contest/prepare-to-change-this-re… #4
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 and Deploy to Dev server | |
on: | |
push: | |
branches: | |
- master | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
tags: hsukju00/towork-api | |
- name: Upload docker-compose.dev.yml | |
uses: actions/upload-artifact@v3 | |
with: | |
name: docker-artifact | |
path: | | |
docker-compose.yml | |
deploy: | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Download docker-compose.yml | |
uses: actions/download-artifact@v3 | |
with: | |
name: docker-artifact | |
path: ./ | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add remote server to known hosts | |
run: | | |
mkdir -p ~/.ssh | |
ssh-keyscan ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
- name: SCP transfer | |
run: | | |
scp ./docker-compose.dev.yml ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:~/docker-compose.yml | |
scp -r .platform ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }}:~/ | |
- name: Execute remote commands | |
run: | | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} "sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/tdwork-api-server" | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} "docker-compose up --build -d" | |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SERVER_IP }} "docker image prune -a -f" |