Skip to content

go-training/gitea-workshop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gitea-workshop

Starting with Gitea 1.19, Gitea Actions are available as a built-in CI/CD solution.

事前準備

  1. 註冊 Docker Hub 帳號
  2. 登入 Play With Docker 平台

也可以在 DigitalOcean 上建立 Droplet,並安裝 Docker.

安裝 Gitea 服務

多種安裝方式可以參考線上文件,我們選擇使用 Installation with Docker (rootless) 方式安裝。

mkdir -p gitea/{data,config}
cd gitea
touch docker-compose.yml
chown 1000:1000 config/ data/
# or chmod 777 config/ data/

打開 docker-compose.yml 檔案,輸入以下內容:

version: "2"

services:
  server:
    image: gitea/gitea:1.20-rootless
    restart: always
    volumes:
      - ./data:/var/lib/gitea
      - ./config:/etc/gitea
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "2222:2222"

你可以將 3000, 2222 替換成你想要的 port。

啟動 Gitea 服務

docker-compose up -d

install gitea

請點選 3000 port 的連結就可以看到首頁了,請參考底下畫面

gitea install page

設定 Administrator 帳號,請參考底下畫面

install administrator

按下送出後,請等待 Install 過程

install process

安裝 Gitea Actions

從 Gitea 1.19 版本開始,Gitea Actions 就已經內建在 Gitea 服務中。請打開 config/app.ini 檔案,並增加底下設定

[actions]
ENABLED=true

請重新啟動 Gitea 服務

docker-compose restart

請點選 Site Administration

click administration link

點選 Runner Tab 選單

create runner

接著透過 docker compose 來啟動 runner 服務,先建立 gitea 資料夾,並建立 docker-compose.yml 檔案

mkdir -p gitea/data
cd gitea
touch docker-compose.yml
sudo chown 1000:1000 data/

打開 docker-compose.yml 檔案,輸入以下內容:

version: "2"

services:
  runner:
    image: gitea/act_runner:0.2.6
    restart: always
    volumes:
      - ./data/act_runner:/data
      - /var/run/docker.sock:/var/run/docker.sock
    environment:
      - GITEA_INSTANCE_URL=<instance url>
      - GITEA_RUNNER_REGISTRATION_TOKEN=<registration token>

請將 <instance url> 替換成你的 Gitea 服務網址,<registration token> 替換成你的 Runner Token。啟動後可以在後台看到底下畫面

gitea runner list

撰寫 Gitea Actions

由於目前 Repository 預設設定都是關閉的,故需要手動開啟。請打開 Repository,點選 Settings,看到左邊選單 Repository,看到右邊設定內找到 Enable Repository Action 點選打勾,最後按下儲存即可。

enable repository action

請建立 .github/workflows 資料夾,並建立 main.yml 檔案

mkdir -p .github/workflows

打開 main.yml 檔案,輸入以下內容:

name: CI
on: [push]
jobs:
  build:
    name: Build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: echo hello world
        run: |
          echo "hello world"

請將 echo hello world 替換成你想要執行的指令,例如 npm installnpm test

About

Starting with Gitea 1.19, Gitea Actions are available as a built-in CI/CD solution.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published