Skip to content

feat: add deployment step #57

feat: add deployment step

feat: add deployment step #57

Workflow file for this run

name: CI
on:
push:
branches:
- 'main'
pull_request:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
lint-frontend:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup nodejs
uses: actions/setup-node@v4
- name: Install dependencies
working-directory: ./frontend
run: npm install
- name: Run linter
working-directory: ./frontend
run: npm run lint
lint-core:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup python
uses: actions/setup-python@v5
with:
cache: 'pip'
- name: Run flake8
uses: py-actions/flake8@v2
with:
exclude: "core/alembic/versions/"
path: "core"
build:
name: Build docker image
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- context: frontend
image: scystream-frontend
- context: core
image: scystream-core
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/${{ matrix.image }}
tags: |
type=ref,event=pr
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
- name: Build and push docker images
uses: docker/build-push-action@v5
with:
context: ${{ matrix.context }}
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
deploy:
name: Deploy Docker containers
runs-on: self-hosted
needs: build
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Write SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SERVER_HOSTNAME }} > ~/.ssh/known_hosts
- name: Pull images
run: |
docker pull ${{ env.REGISTRY }}/rwth-time/${{ env.IMAGE_NAME }}/scystream-frontend:latest
docker pull ${{ env.REGISTRY }}/rwth-time/${{ env.IMAGE_NAME }}/scystream-core:latest
- name: SSH Deploy
run: |
ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@{{ secrets.SERVER_HOSTNAME }} << 'EOF'
docker compose down && docker compose up -d
EOF