Skip to content

Instantly share code, notes, and snippets.

@vaso991
Created April 30, 2022 19:15
Show Gist options
  • Save vaso991/0feaa57bfba3748c85656b40f5128b88 to your computer and use it in GitHub Desktop.
Save vaso991/0feaa57bfba3748c85656b40f5128b88 to your computer and use it in GitHub Desktop.
name: Deploy Docker to server using github registry
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
DOCKER_NAME: app-backend
jobs:
staging:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@master
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Pull and run Docker image on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_KEY }}
port: 22
script: |
cd /opt/triber-backend
docker-compose pull
docker-compose down
docker-compose up -d
docker system prune -af
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment