Closed6

GiteaでプライベートレジストリをActionsで使う

syakesabasyakesaba
name: docker_build_and_push
on:
  workflow_dispatch: # Workflow手動実行を可能にする
  workflow_call:
    inputs:
      DOCKER_REGISTRY:
        description: 'Github Container Registry'
        required: true
        type: string
      DOCKER_IMAGE_NAME:
        description: 'Github Container Registry Repository Name'
        required: true
        type: string
      DOCKER_USERNAME:
        description: 'Github Container Registry UserName'
        required: true
        type: string
      DOCKER_WILL_PUSH:
        description: 'Whether Should Push Container Image to Registry or NOT'
        required: true
        type: boolean
    secrets:
      DOCKER_PASSWORD:
        required: true
jobs:
  main:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: bash
    permissions:
      contents: read # Github Code Repository
      packages: write # Github Container Registry
    steps:
      -
        name: Show Environments For Debug
        run: |
          set -x
          export
      -
        name: Check out source repository
        uses: actions/checkout@v4 # https://github.com/actions/checkout
        with:
          fetch-depth: 1 # shallow clone
      -
        name: Set up QEMU
        uses: docker/setup-qemu-action@v2
      -
        name: Set up Docker BuildX
        uses: docker/setup-buildx-action@v2
        with:
          config-inline: |
            [registry."yourdomain.com"]
              insecure = true
              ca=["/etc/ssl/certs/ca-certificates.crt"]   
      - 
        name: Login to Gitea Container Registry
        uses: docker/login-action@v3 # https://github.com/docker/login-action
        with:
          registry: ${{ inputs.DOCKER_REGISTRY }}
          username: ${{ inputs.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}
      -
        name: Build and push
        uses: docker/build-push-action@v6 # https://github.com/docker/build-push-action
        with:
          context: ./dev
          push: ${{ inputs.DOCKER_WILL_PUSH }}
          tags: ${{ inputs.DOCKER_REGISTRY }}/${{ inputs.DOCKER_IMAGE_NAME }}:latest # ${{ steps.meta.outputs.tags }}
          # labels: ${{ steps.meta.outputs.labels }}
          # cache-from: type=registry,ref=${{ inputs.DOCKER_REGISTRY }}/${{ inputs.DOCKER_IMAGE_NAME }}:buildcache
          # cache-to: type=registry,ref=${{ inputs.DOCKER_REGISTRY }}/${{ inputs.DOCKER_IMAGE_NAME }}:buildcache,mode=max
syakesabasyakesaba

runner側: doodを使用。dockerとgit関係の設定もコンテナ側にマウント。

docker run \
    -v $PWD/config.yaml:/config.yaml \
    -v $PWD/data:/data \
    -v /var/run/docker.sock:/var/run/docker.sock \
    -v /etc/docker:/etc/docker \
    -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro \
    -v /root/act_runner/.gitconfig:/root/.gitconfig \
    -v /root/act_runner/.docker:/root/.docker \
    -e CONFIG_FILE=/config.yaml \
    -e GITEA_INSTANCE_URL=https://yourdomain.com \
    -e GITEA_RUNNER_REGISTRATION_TOKEN=xxxxxxxxxxxxxxxxx \
    -e GITEA_RUNNER_NAME=xxxxxxxxx \
    -e GITEA_RUNNER_LABELS=xxxx \
    --name xxxxxxxxxxxxx \
    --restart always \
    -d \
    gitea/act_runner:nightly
syakesabasyakesaba

config.yaml
マウントを意図的に指定

  # options:
  options: "-v /root/act_runner/.docker:/root/.docker -v /root/act_runner/.gitconfig:/root/.gitconfig -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro -e NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt"
  valid_volumes:
    - "/etc/ssl/certs/ca-certificates.crt"
    - "/root/act_runner/.gitconfig"
    - "/root/act_runner/.docker"
# Example configuration file, it's safe to copy this as the default config file without any modification.

# You don't have to copy this file to your instance,
# just run `./act_runner generate-config > config.yaml` to generate a config file.

log:
  # The level of logging, can be trace, debug, info, warn, error, fatal
  level: info

runner:
  # Where to store the registration result.
  file: .runner
  # Execute how many tasks concurrently at the same time.
  capacity: 1
  # Extra environment variables to run jobs.
  envs:
    A_TEST_ENV_NAME_1: a_test_env_value_1
    A_TEST_ENV_NAME_2: a_test_env_value_2
  # Extra environment variables to run jobs from a file.
  # It will be ignored if it's empty or the file doesn't exist.
  env_file: .env
  # The timeout for a job to be finished.
  # Please note that the Gitea instance also has a timeout (3h by default) for the job.
  # So the job could be stopped by the Gitea instance if it's timeout is shorter than this.
  timeout: 3h
  # The timeout for the runner to wait for running jobs to finish when shutting down.
  # Any running jobs that haven't finished after this timeout will be cancelled.
  shutdown_timeout: 0s
  # Whether skip verifying the TLS certificate of the Gitea instance.
  # insecure: false
  insecure: false
  # The timeout for fetching the job from the Gitea instance.
  fetch_timeout: 5s
  # The interval for fetching the job from the Gitea instance.
  fetch_interval: 2s
  # The labels of a runner are used to determine which jobs the runner can run, and how to run them.
  # Like: "macos-arm64:host" or "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
  # Find more images provided by Gitea at https://gitea.com/gitea/runner-images .
  # If it's empty when registering, it will ask for inputting labels.
  # If it's empty when execute `daemon`, will use labels in `.runner` file.
  labels:
    - "ubuntu-latest:docker://gitea/runner-images:ubuntu-latest"
    - "ubuntu-22.04:docker://gitea/runner-images:ubuntu-22.04"
    - "ubuntu-20.04:docker://gitea/runner-images:ubuntu-20.04"

cache:
  # Enable cache server to use actions/cache.
  enabled: true
  # The directory to store the cache data.
  # If it's empty, the cache data will be stored in $HOME/.cache/actcache.
  dir: ""
  # The host of the cache server.
  # It's not for the address to listen, but the address to connect from job containers.
  # So 0.0.0.0 is a bad choice, leave it empty to detect automatically.
  host: ""
  # The port of the cache server.
  # 0 means to use a random available port.
  port: 0
  # The external cache server URL. Valid only when enable is true.
  # If it's specified, act_runner will use this URL as the ACTIONS_CACHE_URL rather than start a server by itself.
  # The URL should generally end with "/".
  external_server: ""

container:
  # Specifies the network to which the container will connect.
  # Could be host, bridge or the name of a custom network.
  # If it's empty, act_runner will create a network automatically.
  network: ""
  # Whether to use privileged mode or not when launching task containers (privileged mode is required for Docker-in-Docker).
  privileged: false
  # And other options to be used when the container is started (eg, --add-host=my.gitea.url:host-gateway).
  # options:
  options: "-v /root/act_runner/.docker:/root/.docker -v /root/act_runner/.gitconfig:/root/.gitconfig -v /etc/ssl/certs/ca-certificates.crt:/etc/ssl/certs/ca-certificates.crt:ro -e NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt"
  valid_volumes:
    - "/etc/ssl/certs/ca-certificates.crt"
    - "/root/act_runner/.gitconfig"
    - "/root/act_runner/.docker"
  # The parent directory of a job's working directory.
  # NOTE: There is no need to add the first '/' of the path as act_runner will add it automatically.
  # If the path starts with '/', the '/' will be trimmed.
  # For example, if the parent directory is /path/to/my/dir, workdir_parent should be path/to/my/dir
  # If it's empty, /workspace will be used.
  workdir_parent:
  # Volumes (including bind mounts) can be mounted to containers. Glob syntax is supported, see https://github.com/gobwas/glob
  # You can specify multiple volumes. If the sequence is empty, no volumes can be mounted.
  # For example, if you only allow containers to mount the `data` volume and all the json files in `/src`, you should change the config to:
  # valid_volumes:
  #   - data
  #   - /src/*.json
  # If you want to allow any volume, please use the following configuration:
  # valid_volumes:
  #   - '**'
  # valid_volumes: []
  # overrides the docker client host with the specified one.
  # If it's empty, act_runner will find an available docker host automatically.
  # If it's "-", act_runner will find an available docker host automatically, but the docker host won't be mounted to the job containers and service containers.
  # If it's not empty or "-", the specified docker host will be used. An error will be returned if it doesn't work.
  docker_host: ""
  # Pull docker image(s) even if already present
  force_pull: true
  # Rebuild docker image(s) even if already present
  force_rebuild: false

host:
  # The parent directory of a job's working directory.
  # If it's empty, $HOME/.cache/act/ will be used.
  workdir_parent:
syakesabasyakesaba

.gitconfigではhttps変換、認証設定

[url "https://username:PAT@yourdomain.com"]
    insteadOf = http://yourdomain.com
syakesabasyakesaba

/etc/docker/daemon.json

{
    "insecure-registries" : [ "yourdomain.com" ]
}

オレオレ証明書を格納

/etc/docker/cert.d/yourdomain.com/ca.crt
/etc/docker/cert.d/yourdomain.com/client.key

/root/.docker/config.json

ホスト側と内容同期
syakesabasyakesaba

gitea側

helm install gitea gitea-charts/gitea \
  --set gitea.admin.username=yourname \
  --set gitea.admin.password=yourpass \
  --set-literal gitea.admin.email="yourmail" \
  --set gitea.admin.passwordMode=initialOnlyRequireReset \
  --set gitea.config.database.DB_TYPE=postgres \
  --set gitea.config.mailer.ENABLED=true \
  --set-literal gitea.config.mailer.FROM="no-reply@yourdomain.com" \
  --set gitea.config.mailer.PROTOCOL="smtp" \
  --set gitea.config.mailer.SMTP_ADDR="your smtp" \
  --set gitea.config.mailer.SMTP_PORT=25 \
  --set-literal gitea.config.database.HOST="cnpgcluster-rw.cnpg.svc.cluster.local:5432" \
  --set gitea.config.database.NAME=gitea \
  --set gitea.config.database.USER=gitea \
  --set gitea.config.database.PASSWD=gitea \
  --set-literal gitea.config.server.ROOT_URL="https://yourdomain.com/" \
  --set-literal gitea.config.server.DOMAIN="yourdomain.com" \
  --set gitea.config.packages.ENABLED=true \
  --set gitea.config.actions.ENABLED=true \
  --set postgresql-ha.enabled=false
このスクラップは6ヶ月前にクローズされました