Skip to content

Commit

Permalink
Adding deployment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mmolenda committed Jul 14, 2023
1 parent 1dcd40f commit 17daea7
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: Deploy Docker image

on:
push:
tags:
- v*-alpha*

release:
types:
- published

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
deploy:
runs-on: ubuntu-latest
environment: ${{ github.event_name == 'release' && 'production' || 'staging' }}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Install and run Docker image on the server
uses: fifsky/ssh-action@master
with:
command: |
docker pull ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
docker stop $(docker ps | grep ${{ env.IMAGE_NAME }} | cut -d' ' -f1) || true
docker run -d -p ${{ vars.DOCKER_EXPOSED_PORT }}:8000 ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
host: ${{ vars.DEPLOY_HOST }}
port: ${{ vars.DEPLOY_PORT }}
user: ${{ vars.DEPLOY_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY}}

- name: Purge Cloudflare cache
uses: fjogeleit/http-request-action@v1
if: ${{ github.event_name == 'release' }}
with:
url: https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache
method: POST
customHeaders: '{"Content-Type": "application/json"}'
bearerToken: ${{ secrets.CLOUDFLARE_TOKEN }}
data: '{"purge_everything": true}'
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python application
name: Run tests

on:
push:
branches: [ master ]
branches:
- master
- release/*
pull_request:
branches: [ master ]

Expand Down

0 comments on commit 17daea7

Please sign in to comment.