Using gitea actions to deploy my project "netlify" on my server

Hey everyone, I hope you all enjoyed your weekend!

My setup:

  • I’ve set up a Gitea instance with actions enabled on my home server.
  • I manage several JavaScript projects, which are currently hosted on Netlify or other cloud providers. These projects are built automatically when I push updates to my Gitea repositories.
  • I have a Gitea runner already operational, which efficiently handles deployments to Netlify.

This is the docker-compose.yaml for the runner:

GNU nano 6.2                                                                                                                                                     docker-compose.yml                                                                                                                                                               
version: "3.8"
services:
  runner:
    image: gitea/act_runner:latest
    restart: always
    environment:
      CONFIG_FILE: /config.yaml
      GITEA_INSTANCE_URL: "https://git.myDomain.com"
      GITEA_RUNNER_REGISTRATION_TOKEN: "supersecrettoken"
      GITEA_RUNNER_NAME: "gitea-runner-1"
      GITEA_RUNNER_LABELS: "ubuntu-latest:docker://node:16-bullseye,ubuntu-22.04:docker://node:16-bullseye,ubuntu-20.04:docker://node:16-bullseye,ubuntu-18.04:docker://node:16-buster,cth-ubuntu-latest:docker://catthehacker/>"
    volumes:
      - ./config.yaml:/config.yaml
      - ./data:/data
      - /var/run/docker.sock:/var/run/docker.sock

Objective:
I aim to become less dependent on external cloud providers like Netlify or Vercel by hosting my projects directly on my server, accessible via projectName.myDomain.com. This are all private projects, so this is not supposed to be professional or have 99% reliability. Handling HTTPS/certificate configurations manually through my Caddyfile (as I use Caddy as a reverse proxy) is not an issue for me and handling this automatically should not be a topic of this discussion (as I think this will blow this issue out of control :D). Each of my projects contains a Dockerfile for building a container that hosts the application. My goal is to have Gitea actions automatically build or update these containers with each commit.

However, I lack experience with GitHub actions. Could anyone provide guidance or suggestions on how to proceed? Is my goal feasible with Gitea actions, or are there better approaches I should consider?

I somehow made it work, it’s ugly, but it works:

#
# .gitea/publish_local.yaml
#



name: Build And Test
run-name: ${{ gitea.actor }} is runs ci pipeline
on: [push]

jobs:
    build:
        runs-on: ubuntu-latest
        steps:
            - uses: https://github.com/actions/checkout@v4
            - name: Use Node.js
              uses: https://github.com/actions/setup-node@v3
              with:
                  node-version: '18.17'
            - run: npm ci
              env:
                  NODE_OPTIONS: --max_old_space_size=4096

    publish:
        runs-on: cth-ubuntu-latest
        needs: build
        steps:
            - name: Login to Docker Hub
              uses: docker/login-action@v3
              with:
                  username: <DOCKER HUB USERNAME>
                  password: <DOCKER HUB PW>
            - uses: https://github.com/actions/checkout@v4
            - name: Set up Docker Buildx
              uses: https://github.com/docker/setup-buildx-action@v3
              with:
                  config-inline: |
                      [registry."192.168.178.31:3001"] # IP from local gitea instance
                        http = true
                        insecure = true
            - name: Build and push Docker image
              uses: https://github.com/docker/build-push-action@v5
              with:
                  context: .
                  file: ./Dockerfile
                  push: true
                  tags: <TAG FROM DOCKER HUB>
            - name: Stop the docker container
              continue-on-error: true
              run: sudo docker stop homepage
            - name: Remove the docker container
              run: sudo docker rm homepage
            - name: Pull the Docker image
              # if: always()
              run: sudo docker pull USERNAME/IMAGE:latest
            - name: Run the Docker container
              run: sudo docker run -d --network caddy --name homepage -p 7777:80 USERNAME/IMAGE:latest

This builds a docker image on push to repository. It then pushes it to your Docker Hub. Then your Docker Container is stopped and removed (if you deploy this the first time it ignores the error that the container with the given name can not be found). After that the fresh Docker images gets pulled from your Docker Hub and then started with a couple of parameters (connect to my reverse proxy network, give it a unique name so the container can be found on next push and let it run in the background so the pipeline can finish).

Hope that helps. If any of you pros find some improvements, feel free to teach me.

PS: The Jobs are a mess, build job is useless and the steps on the publish job could possibly all be combined in one step

1 Like