From 8bce1cb670106519f2cea1b2642ce1ab66f976c4 Mon Sep 17 00:00:00 2001 From: Chris Anderson Date: Wed, 24 Jun 2026 09:57:20 +0200 Subject: [PATCH] Switch from GitHub Actions to self-hosted Gitea CI/CD - Removed .github/workflows/deploy.yml (GitHub Actions) - Added .gitea/workflows/deploy.yml (Gitea Actions) - Added setup-gitea.sh for installing Gitea - Added configure-gitea.sh for configuring Gitea - Self-hosted Git + CI/CD on local server - GitHub org only for final open-source projects Co-Authored-By: Paperclip --- .gitea/workflows/deploy.yml | 38 ++++++++++++++++++++++ .github/workflows/deploy.yml | 63 ------------------------------------ configure-gitea.sh | 53 ++++++++++++++++++++++++++++++ setup-gitea.sh | 54 +++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 63 deletions(-) create mode 100644 .gitea/workflows/deploy.yml delete mode 100644 .github/workflows/deploy.yml create mode 100755 configure-gitea.sh create mode 100755 setup-gitea.sh diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 00000000..05bb3f6a --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,38 @@ +name: Deploy hatch.surf + +on: + push: + branches: [main] + workflow_dispatch: + +env: + IMAGE_NAME: hatch-web + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build Docker image + run: | + docker build -t ${{ env.IMAGE_NAME }}:${{ github.sha }} . + docker tag ${{ env.IMAGE_NAME }}:${{ github.sha }} ${{ env.IMAGE_NAME }}:latest + + - name: Deploy to server + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + cd /home/nara/repos/hatch-surf + git pull origin main + docker compose build + docker compose up -d --remove-orphans + docker system prune -f diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index ef1d308c..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: Deploy hatch.surf - -on: - push: - branches: [main] - workflow_dispatch: - -env: - REGISTRY: ghcr.io - IMAGE_NAME: ${{ github.repository }}/hatch-web - -jobs: - build-and-push: - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Log in to Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ env.REGISTRY }} - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata - id: meta - uses: docker/metadata-action@v5 - with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - tags: | - type=sha - type=ref,event=branch - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - - deploy: - needs: build-and-push - runs-on: ubuntu-latest - - steps: - - name: Deploy to server - uses: appleboy/ssh-action@v1 - with: - host: ${{ secrets.SERVER_HOST }} - username: ${{ secrets.SERVER_USER }} - key: ${{ secrets.SERVER_SSH_KEY }} - script: | - cd /home/nara/repos/hatch-surf - git pull origin main - docker compose pull - docker compose up -d --remove-orphans - docker system prune -f diff --git a/configure-gitea.sh b/configure-gitea.sh new file mode 100755 index 00000000..827ecda7 --- /dev/null +++ b/configure-gitea.sh @@ -0,0 +1,53 @@ +#!/bin/bash +# Configure Gitea for El Foundation +# Run after initial Gitea setup + +set -e + +GITEA_URL="http://localhost:3000" +GITEA_TOKEN="${GITEA_TOKEN:-your-admin-token}" + +echo "=== Configuring Gitea for El Foundation ===" + +# Create organization +echo "Creating El Foundation organization..." +curl -X POST "$GITEA_URL/api/v1/orgs" \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "username": "el-foundation", + "full_name": "El Foundation", + "description": "El Foundation - Open Source Projects", + "website": "", + "location": "", + "visibility": "public" + }' + +# Create hatch-surf repository +echo "Creating hatch-surf repository..." +curl -X POST "$GITEA_URL/api/v1/orgs/el-foundation/repos" \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "hatch-surf", + "description": "Hatch.surf web application", + "private": false, + "auto_init": false, + "default_branch": "main" + }' + +# Add remote to local repo +echo "Adding Gitea remote to local repo..." +cd /home/nara/apps/web +git remote add origin http://localhost:3000/el-foundation/hatch-surf.git +git push -u origin main + +echo "" +echo "=== Configuration Complete ===" +echo "Repository: $GITEA_URL/el-foundation/hatch-surf" +echo "" +echo "To enable Gitea Actions (CI/CD):" +echo "1. Go to repository Settings > Actions" +echo "2. Enable Actions" +echo "3. Add secrets: SERVER_HOST, SERVER_USER, SERVER_SSH_KEY" +echo "4. Push to main branch to trigger deployment" diff --git a/setup-gitea.sh b/setup-gitea.sh new file mode 100755 index 00000000..e7aa3057 --- /dev/null +++ b/setup-gitea.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# Gitea Setup Script for El Foundation +# Self-hosted Git + CI/CD + +set -e + +GITEA_VERSION="1.22" +GITEA_PORT="3000" +GITEA_DATA="/var/lib/gitea" +GITEA_CONFIG="/etc/gitea" + +echo "=== Setting up Gitea for El Foundation ===" + +# Install Gitea +echo "Installing Gitea..." +wget -O /usr/local/bin/gitea https://dl.gitea.com/gitea/${GITEA_VERSION}.0/gitea-${GITEA_VERSION}.0-linux-amd64 +chmod +x /usr/local/bin/gitea + +# Create directories +sudo mkdir -p $GITEA_DATA $GITEA_CONFIG +sudo chown -R nara:nara $GITEA_DATA $GITEA_CONFIG + +# Create systemd service +cat > /tmp/gitea.service << 'EOF' +[Unit] +Description=Gitea (Git with a cup of tea) +After=network.target + +[Service] +Type=simple +User=nara +Group=nara +WorkingDirectory=/var/lib/gitea +ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini +Restart=always +Environment=USER=nara HOME=/home/nara GITEA_WORK_DIR=/var/lib/gitea + +[Install] +WantedBy=multi-user.target +EOF + +sudo mv /tmp/gitea.service /etc/systemd/system/ +sudo systemctl daemon-reload +sudo systemctl enable gitea +sudo systemctl start gitea + +echo "Gitea installed and started on port $GITEA_PORT" +echo "Access at http://localhost:$GITEA_PORT" +echo "" +echo "Next steps:" +echo "1. Open http://localhost:$GITEA_PORT in browser" +echo "2. Complete initial setup" +echo "3. Create admin account" +echo "4. Run: ./configure-gitea.sh"