First try forgejo actions

After moving to forgejo, i want to try the forgejo actions. First repo should be this website, which gets build with pelican, since this year.

The repo setup was quite easy, but the learning from my former drone-ci implementation to forgejo actions took me quite a few evenings to accomplish the following:

  • Preparing a docker image with all needed packages, ended up with:
    • base image node:22-bookworm-slim
    • copy/add the needed files
    • installing needed packages (forgot several each step ...)
    • make virtualenv (with pelican and all other requirements)
    • install the correct theme in container/virtualenv
  • Cloning the repo into the docker container
  • Build the project
  • Prepare SSH Host Keys/known hosts
  • Deploy the website with rsync/ssh

My used Dockerfile:

FROM node:22-bookworm-slim

COPY Makefile .
COPY requirements.txt .
ADD new-bootstrap2 /new-bootstrap2

RUN apt-get update
RUN apt-get -y install git python3 python3-pip python3-virtualenv rsync
RUN make env
RUN . /.venv/bin/activate && pelican-themes -i /new-bootstrap2

and my corresponding .forgejo/workflows/build.yml file:

name: build

on:
  push:
    branches:
      - 'main'
      - 'master'

jobs:
  build_deploy:
    runs-on: docker
    container:
      image: weiti.org-pelican:20241216.1

    steps:

        - uses: https://code.forgejo.org/actions/checkout@v4

        - name: Build the project
          shell: bash
          run: ". /.venv/bin/activate && make html"

        - name: Install SSH Key
          uses: https://github.com/shimataro/ssh-key-action@v2
          with:
            key: ${{ secrets.SSH_PRIVATE_KEY }}
            known_hosts: unnecessary

        - name: Adding Known Hosts
          run: ssh-keyscan -p ${{ secrets.SSH_PORT }} -H ${{ secrets.SSH_HOST }} >> ~/.ssh/known_hosts

        - name: Deploy website
          run: ". /.venv/bin/activate && make rsync_upload"

The build docker image is installed in my registered runner, therefore i don't need to install/prepare everything every run.

docker build -t weiti.org-pelican:20241216.1 .