Skip to content

Backend CI

Backend CI #124

Workflow file for this run

name: Backend CI
on:
push:
paths:
- "backend/**"
- ".github/workflows/backend.yml"
workflow_dispatch:
env:
IMAGE_NAME_PREFIX: ghcr.io/plone/tagung.plone.de
IMAGE_NAME_SUFFIX: backend
PYTHON_VERSION: "3.12"
STACK_PARAM: latest
STACK_NAME: testingtagung-plone-de
STACK_PREFIX: testingtagung_plonede
PUBLIC_URL: testingtagung.plone.de
CERTRESOLVER: le-cloudflare
STACK_FILE: devops/stacks/testingtagung.plone.de.yml
jobs:
meta:
runs-on: ubuntu-latest
outputs:
PLONE_VERSION: ${{ steps.vars.outputs.PLONE_VERSION }}
DEPLOY_ENVIRONMENT: ${{ steps.vars.outputs.DEPLOY_ENVIRONMENT }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set Env Vars
id: vars
run: |
echo "TAG=$(cat version.txt)" >> $GITHUB_OUTPUT
echo "PLONE_VERSION=$(cat backend/version.txt)" >> $GITHUB_OUTPUT
echo "DEPLOY_ENVIRONMENT=${{ env.PUBLIC_URL }}" >> $GITHUB_OUTPUT
- name: Test vars
run: |
echo "TAG=${{ steps.vars.outputs.TAG }}"
echo "PLONE_VERSION=${{ steps.vars.outputs.PLONE_VERSION }}"
echo "DEPLOY_ENVIRONMENT=${{ steps.vars.outputs.DEPLOY_ENVIRONMENT }}"
black:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Run check
uses: plone/code-analysis-action@v2
with:
base_dir: 'backend'
check: 'black'
flake8:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Run check
uses: plone/code-analysis-action@v2
with:
base_dir: 'backend'
check: 'flake8'
zpretty:
runs-on: ubuntu-latest
needs:
- meta
steps:
- name: Checkout codebase
uses: actions/checkout@v4
- name: Run check
uses: plone/code-analysis-action@v2
with:
base_dir: 'backend'
check: 'zpretty'
tests:
runs-on: ubuntu-latest
needs:
- meta
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Setup Plone ${{ needs.meta.outputs.PLONE_VERSION }} with Python ${{ env.PYTHON_VERSION }}
uses: plone/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}
plone-version: ${{ needs.meta.outputs.PLONE_VERSION }}
additional-packages: mxdev
- name: Install Project packages
run: |
mxdev -c mx.ini
pip install -r requirements-mxdev.txt
- name: Run tests
run: |
pytest --disable-warnings tests
release:
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
needs:
- meta
- black
- flake8
- zpretty
- tests
permissions:
contents: read
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}
labels: |
org.label-schema.docker.cmd=docker run -d -p 8080:8080 ${{ env.IMAGE_NAME_PREFIX }}-${{ env.IMAGE_NAME_SUFFIX }}:latest
flavor:
latest=false
tags: |
type=ref,event=branch
type=sha
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v6
with:
platforms: linux/amd64
context: backend
file: backend/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
PLONE_VERSION=${{ needs.meta.outputs.PLONE_VERSION }}
deploy:
if: ${{ github.ref == 'refs/heads/main' }}
concurrency: deploy_testing
needs:
- meta
- release
runs-on: ubuntu-latest
environment:
name: ${{ needs.meta.outputs.DEPLOY_ENVIRONMENT }}
url: https://${{ needs.meta.outputs.DEPLOY_ENVIRONMENT }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Test vars
run: |
echo "DEPLOY_ENVIRONMENT=${{ needs.meta.outputs.DEPLOY_ENVIRONMENT }}"
echo "PLONE_VERSION=${{ needs.meta.outputs.PLONE_VERSION }}"
- name: Deploy to testingtagung.plone.de
uses: kitconcept/[email protected]
with:
registry: 'ghcr.io'
username: ${{ github.actor }}
password: ${{ secrets.DEPLOY_GHCR_READ_TOKEN }}
remote_host: ${{ vars.DEPLOY_HOST }}
remote_port: ${{ vars.DEPLOY_PORT }}
remote_user: ${{ vars.DEPLOY_USER }}
remote_private_key: ${{ secrets.DEPLOY_SSH }}
stack_file: ${{ env.STACK_FILE }}
stack_name: ${{ env.STACK_NAME }}
env_file: |
STACK_NAME=${{ env.STACK_NAME }}
STACK_PREFIX=${{ env.STACK_PREFIX }}
PUBLIC_URL=${{ env.PUBLIC_URL }}
CERTRESOLVER=${{ env.CERTRESOLVER }}
BACKEND_IMAGE=${{ env.IMAGE_NAME_PREFIX }}-backend
FRONTEND_IMAGE=${{ env.IMAGE_NAME_PREFIX }}-frontend
DB_HOST=${{ vars.DB_HOST }}
DB_PORT=${{ vars.DB_PORT }}
DB_NAME=${{ vars.DB_NAME }}
DB_USER=${{ vars.DB_USER }}
DB_PASSWORD=${{ secrets.DB_PASSWORD }}
BASIC_AUTH_USER=${{ vars.BASIC_AUTH_USER }}
BASIC_AUTH_PASSWORD=${{ vars.BASIC_AUTH_PASSWORD }}
MASTODON_APPS=${{ secrets.MASTODON_APPS }}
deploy_timeout: 480