upgrade workflow #28
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: CI/CD Pipline | |
on: | |
pull_request: | |
branches: | |
- master | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Login to Docker Hub | |
uses: docker/#-action@v1 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v2 | |
with: | |
context: . | |
push: true | |
tags: ${{ secrets.DOCKER_USERNAME }}/serf-bot:latest | |
- name: Install Expect | |
run: sudo apt-get install -y expect | |
- name: Deploy to VPS | |
env: | |
VPS_HOST: ${{ secrets.VPS_HOST }} | |
VPS_USER: ${{ secrets.VPS_USERNAME }} | |
VPS_SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }} | |
VPS_SSH_PRIVATE_KEY_PASSPHRASE: ${{ secrets.VPS_SSH_PRIVATE_KEY_PASSPHRASE }} | |
run: | | |
echo "${{ env.VPS_SSH_PRIVATE_KEY }}" > private_key | |
chmod 600 private_key | |
eval "$(ssh-agent -s)" | |
echo "${{ env.VPS_SSH_PRIVATE_KEY_PASSPHRASE }}" | expect -c "spawn ssh-add private_key; expect \"Enter passphrase:\"; send -- \"${{ env.VPS_SSH_PRIVATE_KEY_PASSPHRASE }}\r\"; expect eof" | |
rm -f private_key | |
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${{ env.VPS_USER }}@${{ env.VPS_HOST }} <<-EOF | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker pull ${{ secrets.DOCKER_USERNAME }}/serf-bot:latest | |
docker stop serf-bot || true | |
docker rm serf-bot || true | |
docker run -d --name serf-bot -p 3005:3005 ${{ secrets.DOCKER_USERNAME }}/serf-bot:latest | |
EOF |