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.

  • ikidd@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    2
    ·
    2 hours ago

    AFAIK, Actions are for building artifacts for the repo that can then be used by other services to deploy. Like it’ll run a Dockerfile to build a new image, but you still need Watchtower to update your running stack from the repo tag.

  • Avid Amoeba@lemmy.ca
    link
    fedilink
    English
    arrow-up
    1
    ·
    2 hours ago

    I’ve used SaltStack since 2018 but am looking into migrating to Ansible. If I used CI/CD, I’d still use Ansible to do the actual deployment work.

  • DionNam@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    14 hours ago

    The error is because the runner container has no docker client and no access to the host’s daemon. The usual fix is to mount /var/run/docker.sock into the runner and use a job image that ships the docker CLI, then docker compose up -d works from the workflow. Keep in mind that socket is basically root on the Pi, so only run workflows you trust.

  • Denys Nykula@piefed.social
    link
    fedilink
    English
    arrow-up
    3
    ·
    18 hours ago

    I have podman-compose on host. A single compose.yaml declares all images that should run and depend on each other. Then there’s a single .env file for config. A systemd user service runs podman-compose up with that .env file. A cron job periodically runs podman-compose pull, stops the systemd service, backups volumes and starts the systemd service back again. For the web app I write, its CI builds a Docker image and pushes it to the Codeberg registry, from which podman-compose picks it up. It’s very far from instant deploy, but works for my needs.

  • WoodYouLookAtThat@lemmy.today
    link
    fedilink
    English
    arrow-up
    7
    ·
    23 hours ago

    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:

    1. forgejo action builds
    2. gitops deploys (doco-cd, komodo, etc)
  • LukeTS@piefed.social
    link
    fedilink
    English
    arrow-up
    4
    ·
    20 hours ago

    This isn’t a direct answer to your question, but maybe you’ll find it helpful. I personally use dokploy to handle this. The approach is a bit different and it works more like vercel and netlify. You point dokploy to your repository and it will pull the code and deploy it.

    I also have a forgejo actions runner (which I actually manage via dokploy), but I mainly use actions to run tests and code checks.

  • Possibly linux@lemmy.zip
    link
    fedilink
    English
    arrow-up
    5
    ·
    edit-2
    22 hours ago

    First make make a script that deploys it. Then convert that script into a workflow. In the end your workflow will be 3 steps:

    1. Checkout the repo
    2. Create SSH key
    3. 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 0

    And 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

    • myrmidex@belgae.social
      link
      fedilink
      English
      arrow-up
      3
      ·
      22 hours ago

      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.

  • yaroto98@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    20 hours ago

    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.

  • ZeroGravitas@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    2
    ·
    23 hours ago

    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.