1
Fork 0

Compare commits

..

3 commits

Author SHA1 Message Date
6d035411c6
Merge branch 'feat/registry-mirror'
All checks were successful
build/frp Building image frp
build/base Building image base
build/fava Building image fava
build/node-script Building image node-script
build/fluentd Building image fluentd
build/python-script Building image python-script
build/gitea Building images gitea-package, gitea-pr, gitea-status
build/gotenberg Building image gotenberg
build/ruby-script Building image ruby-script
build/beancount-import Building image beancount-import
build/lua-clib Building image lua-clib
build/forgejo Building image forgejo
build/nextcloud Building image nextcloud
build/rust-xwin Building image rust-xwin
* feat/registry-mirror:
  feat: Implement repository mirror
  feat: Add registry mirror
2024-08-29 12:02:01 +02:00
a6a9fe59ec
feat: Implement repository mirror
The `oci-build-task` seems to be doing more requests to the registry
than local `docker build`, which frequently results in Docker Hub's
rate limits kicking in.

By proxying `docker.io`, this should hopefully be avoided.

A somewhat elaborate setup and a custom build of `oci-build-task` are
needed: https://github.com/concourse/oci-build-task/pull/121.

Fixes: #39.
2024-08-29 11:58:39 +02:00
2432154339
feat: Add registry mirror
Fixes: #39
2024-08-28 11:51:27 +02:00
6 changed files with 43 additions and 17 deletions

View file

@ -3,6 +3,7 @@ target := 'main'
# Internal endpoint of the Docker registry, where no authentication is necessary # Internal endpoint of the Docker registry, where no authentication is necessary
registry_url := env_var_or_default('REGISTRY_URL', 'docker.io/') registry_url := env_var_or_default('REGISTRY_URL', 'docker.io/')
registry_mirror_url := env_var_or_default('REGISTRY_MIRROR_URL', '')
forgejo_api_key := env_var("FORGEJO_API_KEY") forgejo_api_key := env_var("FORGEJO_API_KEY")
forgejo_url := shell("git remote get-url origin | sed 's|git@\\([^:]*\\):\\(.*\\).git|https://\\1/\\2|' | cut -d'/' -f-3") forgejo_url := shell("git remote get-url origin | sed 's|git@\\([^:]*\\):\\(.*\\).git|https://\\1/\\2|' | cut -d'/' -f-3")
repo_owner := shell("git remote get-url origin | sed 's|git@\\([^:]*\\):\\(.*\\).git|https://\\1/\\2|' | cut -d'/' -f4") repo_owner := shell("git remote get-url origin | sed 's|git@\\([^:]*\\):\\(.*\\).git|https://\\1/\\2|' | cut -d'/' -f4")
@ -10,6 +11,15 @@ repo_name := shell("git remote get-url origin | sed 's|git@\\([^:]*\\):\\(.*\\).
pipeline_file := shell('mktemp') pipeline_file := shell('mktemp')
buildkit_config_tmpl := '''
[registry."docker.io"]
mirrors = ["{{registry_mirror_url}}"]
[registry."{{registry_mirror_url}}"]
http = true
'''
buildkit_config := replace(buildkit_config_tmpl, "{{registry_mirror_url}}", registry_mirror_url)
build context dockerfile='' image_target='' *args='': build context dockerfile='' image_target='' *args='':
fly -t {{target}} execute \ fly -t {{target}} execute \
--config=./tasks/build-image.yml \ --config=./tasks/build-image.yml \
@ -19,6 +29,8 @@ build context dockerfile='' image_target='' *args='':
-v context=repo/images/{{context}} \ -v context=repo/images/{{context}} \
-v dockerfile={{dockerfile}} \ -v dockerfile={{dockerfile}} \
-v target={{image_target}} \ -v target={{image_target}} \
-v registry_url={{registry_url}} \
-v 'buildkit_config={{buildkit_config}}' \
{{args}} {{args}}
make-pipeline file: make-pipeline file:
@ -26,13 +38,19 @@ make-pipeline file:
fly -t {{target}} validate-pipeline \ fly -t {{target}} validate-pipeline \
--strict \ --strict \
--config "{{file}}" \ --config "{{file}}" \
-v registry_url={{registry_url}} -v registry_url={{registry_url}} \
-v 'buildkit_config={{buildkit_config}}' \
-v forgejo_api_key={{forgejo_api_key}} \
-v forgejo_url={{forgejo_url}} \
-v repo_owner={{repo_owner}} \
-v repo_name={{repo_name}}
set-pipeline: (make-pipeline pipeline_file) set-pipeline: (make-pipeline pipeline_file)
fly -t {{target}} set-pipeline \ fly -t {{target}} set-pipeline \
--pipeline {{pipeline_name}} \ --pipeline {{pipeline_name}} \
--config "{{pipeline_file}}" \ --config "{{pipeline_file}}" \
-v registry_url={{registry_url}} \ -v registry_url={{registry_url}} \
-v 'buildkit_config={{buildkit_config}}' \
-v forgejo_api_key={{forgejo_api_key}} \ -v forgejo_api_key={{forgejo_api_key}} \
-v forgejo_url={{forgejo_url}} \ -v forgejo_url={{forgejo_url}} \
-v repo_owner={{repo_owner}} \ -v repo_owner={{repo_owner}} \

View file

@ -1,5 +1,5 @@
{%- import 'jobs/simple-image.yml.j2' as simple_image %} {%- import 'jobs/simple-image.yml.j2' as simple_image %}
{%- macro simple_image_resource(name, registry_url) -%} {%- macro simple_image_resource(name) -%}
- name: status-{{name}} - name: status-{{name}}
type: gitea-status type: gitea-status
source: source:
@ -15,7 +15,7 @@
type: registry-image type: registry-image
icon: docker icon: docker
source: source:
repository: "{{ registry_url }}/{{ name }}" repository: "((registry_url))/{{ name }}"
tag: latest tag: latest
{% endmacro -%} {% endmacro -%}
--- ---
@ -39,13 +39,12 @@ resources:
uri: ((forgejo_url))/((repo_owner))/((repo_name)) uri: ((forgejo_url))/((repo_owner))/((repo_name))
branch: master branch: master
{%- set registry_url = "((registry_url))" %}
{% for img in images -%} {% for img in images -%}
{%- if img.type == "simple" %} {%- if img.type == "simple" %}
{{ simple_image_resource(img.name, registry_url) }} {{ simple_image_resource(img.name) }}
{%- elif img.type == "file" %} {%- elif img.type == "file" %}
{%- import "jobs/" + img.name + ".yml.j2" as job %} {%- import "jobs/" + img.name + ".yml.j2" as job %}
{{ job.resources(registry_url) }} {{ job.resources() }}
{%- endif %} {%- endif %}
{%- endfor %} {%- endfor %}

View file

@ -1,9 +1,9 @@
{% macro resource(variant, registry_url) -%} {% macro resource(variant) -%}
- name: image-gitea-{{ variant }} - name: image-gitea-{{ variant }}
type: registry-image type: registry-image
icon: docker icon: docker
source: source:
repository: "{{ registry_url }}/gitea-{{ variant }}" repository: "((registry_url))/gitea-{{ variant }}"
tag: latest tag: latest
{% endmacro %} {% endmacro %}
@ -15,6 +15,8 @@
context: repo/images/gitea context: repo/images/gitea
target: '' target: ''
dockerfile: '' dockerfile: ''
registry_url: "((registry_url))"
buildkit_config: "((buildkit_config))"
params: params:
BUILD_ARG_VARIANT: {{ variant }} BUILD_ARG_VARIANT: {{ variant }}
output_mapping: output_mapping:
@ -28,7 +30,7 @@
no_get: true no_get: true
{% endmacro %} {% endmacro %}
{% macro resources(registry_url) -%} {% macro resources() -%}
- name: status-gitea - name: status-gitea
type: gitea-status type: gitea-status
source: source:
@ -40,12 +42,12 @@
context: build/gitea context: build/gitea
description: Building images gitea-package, gitea-pr, gitea-status description: Building images gitea-package, gitea-pr, gitea-status
{{ resource('package', registry_url) }} {{ resource('package') }}
{{ resource('status', registry_url) }} {{ resource('status') }}
{{ resource('pr', registry_url) }} {{ resource('pr') }}
{% endmacro %} {% endmacro %}
{% macro jobs() -%} {% macro jobs(registry_url) -%}
- name: gitea - name: gitea
serial: true serial: true
on_success: on_success:

View file

@ -1,4 +1,4 @@
{% macro resources(registry_url) -%} {% macro resources() -%}
- name: status-rust-xwin - name: status-rust-xwin
type: gitea-status type: gitea-status
source: source:
@ -14,14 +14,14 @@
type: registry-image type: registry-image
icon: docker icon: docker
source: source:
repository: "{{ registry_url }}/rust-xwin" repository: "((registry_url))/rust-xwin"
tag: latest tag: latest
- name: image-rust-xwin-ci - name: image-rust-xwin-ci
type: registry-image type: registry-image
icon: docker icon: docker
source: source:
repository: "{{ registry_url }}/rust-xwin-ci" repository: "((registry_url))/rust-xwin-ci"
tag: latest tag: latest
{% endmacro %} {% endmacro %}
@ -62,6 +62,8 @@
context: repo/images/rust-xwin context: repo/images/rust-xwin
target: rust-xwin target: rust-xwin
dockerfile: '' dockerfile: ''
registry_url: "((registry_url))"
buildkit_config: "((buildkit_config))"
output_mapping: output_mapping:
image: image-rust-xwin image: image-rust-xwin
- task: build-rust-xwin-ci - task: build-rust-xwin-ci
@ -71,6 +73,8 @@
context: repo/images/rust-xwin context: repo/images/rust-xwin
target: rust-xwin-ci target: rust-xwin-ci
dockerfile: '' dockerfile: ''
registry_url: "((registry_url))"
buildkit_config: "((buildkit_config))"
output_mapping: output_mapping:
image: image-rust-xwin-ci image: image-rust-xwin-ci
- in_parallel: - in_parallel:

View file

@ -35,6 +35,8 @@
context: repo/images/{{ job.name }} context: repo/images/{{ job.name }}
dockerfile: '' dockerfile: ''
target: '' target: ''
registry_url: "((registry_url))"
buildkit_config: "((buildkit_config))"
{%- if "args" in job %} {%- if "args" in job %}
params: params:
{%- for name, value in job.args.items() %} {%- for name, value in job.args.items() %}

View file

@ -6,7 +6,7 @@ image_resource:
name: image name: image
type: registry-image type: registry-image
source: source:
repository: concourse/oci-build-task repository: ((registry_url))/oci-build-task
tag: latest tag: latest
inputs: inputs:
@ -23,6 +23,7 @@ params:
CONTEXT: ((context)) CONTEXT: ((context))
DOCKERFILE: ((dockerfile)) DOCKERFILE: ((dockerfile))
TARGET: ((target)) TARGET: ((target))
BUILDKIT_EXTRA_CONFIG: ((buildkit_config))
run: run:
path: build path: build