deployment #56
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: Deploy to server | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Build Docker image | |
run: | | |
docker buildx build --platform linux/amd64 -t bluescript:latest . | |
- name: Save Docker image as tarball | |
run: | | |
docker save bluescript:latest | gzip > bluescript.tar.gz | |
- name: Set up SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Add server to known_hosts | |
run: ssh-keyscan -H ${{ secrets.SERVER_IP }} >> ~/.ssh/known_hosts | |
- name: Transfer Docker image to server | |
run: | | |
scp bluescript.tar.gz ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:${{ secrets.SERVER_DEPLOY_PATH }} | |
- name: Deploy Docker container on server | |
run: | | |
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'ENDSSH' | |
cd ${{ secrets.SERVER_DEPLOY_PATH }} | |
gunzip -c bluescript.tar.gz | sudo docker load | |
sudo docker stop bluescript || true | |
sudo docker rm bluescript || true | |
sudo docker run -d --name bluescript --network web bluescript:latest | |
sudo docker system prune -f --volumes | |
ENDSSH |