I’ve been trying to figure this part out for a few days. I have my own Forgejo instance and a website each running in separate containers on a Raspberry Pi. I also have the forgejo runner installed in another docker container. I followed some guides to set up forgejo actions, but all the guides end with a simple example that basically just runs the “ls” command.
I tried running ‘docker compose up’ inside my workflow, but it fails with “docker: command not found”. So how do you use the workflow to actually update the website in the other container?
I think I’d prefer keeping everything in docker but I’d be okay with making the workflow run some script on the host machine if needed.
Creare a step before your ‘docker compose up’ that does a apt get update apt get upgrade and then installs docker and docker compose.
Every time the action runs you are going to get a brand new clean ephemeral environment. You can shortcut the install steps by pointing it to an existing container that has docker isntalled on it, or building one yourself. But the easiest way is to just add a step to install the things you want in the container during the run.
First make make a script that deploys it. Then convert that script into a workflow. In the end your workflow will be 3 steps:
- Checkout the repo
- Create SSH key
- Copy to host and restart service
For the SSH key I would encode it via base64 before storing it as a forgejo secret. You can do via something like this:
cat private.key | base64 -w 0And then in your workflow
echo $APP_SSH_KEY | base64 -d > ~/.ssh/id_ed25519(assuming you use ed25519 which is the default key)I would also advise moving away from docker in favor of podman since docker uses root by default
Another approach could be pushing to the forgejo container registry and then setting your docker host to auto update
pushing to the forgejo container registry and then setting your docker host to auto update
This is what I prefer, with version tags instead of latest. Then I update the tag manually in the compose file and redeploy, but that could indeed easily be :latest+watchtower, full auto.
The error comes from the fact that you run the forgejo runner with an image that doesn’t have Docker, you’d need docker-in-docker (dind) in that case. But to update the homepage, you need to run docker on the host where it is.
There’s 2 common ways to achieve what you want.
-
on the website host, run an agent that checks out the git repo in intervals (or gets triggered by a forgejo webhook) and deploys it there. A common solution for that is Komodo, but there’s others as well. You don’t need the forgejo runner in this scenario, at least not for the deployment, everything is managed by Komodo.
-
in the forgejo runner, you run a script that sshs into the website host and runs docker there, checking out the remote repo and deploys it with docker. A common tool for this is Ansible, which has modules for a lot of cases so you don’t need to cobble together an ugly bash script
-
If you’re running forgejo runner in a docker container, it can only do things inside that container (excepting if it connects to something else). You could give that container access to the docker daemon, but at that point it’s effectively a privileged runner with root access, and I don’t think I would want to do that.
If you install forgejo runner on the host itself and give it access to the docker daemon, it could run docker compose up, but otherwise it’s trying to use an asset that it cannot access.
You could also feasibly have the runner SSH into the target machine and run docker commands from there.
To me, both of these are suboptimal and I would sooner split the job into two phases:
- forgejo action builds
- gitops deploys (doco-cd, komodo, etc)
Not much experience with Forgejo, but for the docker compose part, you can just ssh to the host machine. Guess you’re just depending on :latest for your app, otherwise it won’t work (unless you generate your compose file). The whole script can reside in the pipeline, or in a separate repo on the host, whatever is easier.
Use key auth for ssh and run the whole thing under a non root user that’s part of the docker group. Beware the permissions inside the Web app container too.
deleted by creator




