drone-ci-multiarch-containe.../multiarch-container.yaml

110 lines
2.9 KiB
YAML

{{- range $i, $plat := .input.platforms -}}
---
kind: pipeline
type: kubernetes
name: build-{{ $plat.os }}-{{ $plat.arch }}
trigger:
event: [ push ]
branch: [ {{ if $.input.build_branches -}}{{ range $.input.build_branches }}{{ . }}, {{ end }}{{ else }}master{{- end }} ]
steps:
- name: build
image: plugins/docker
settings:
registry: https://gitea.internal.example.com
username: drone
password:
from_secret: gitea-internal-password
repo: gitea.internal.example.com/{{ $.input.repo }}
cache_from: gitea.internal.example.com/{{ $.input.repo }}:ci-{{ $plat.os }}-{{ $plat.arch }}
build_args:
- OS={{ $plat.os }}
- ARCH={{ $plat.arch }}
{{ range $.input.build_args }}
- {{ . }}
{{ end }}
tags:
- ci-{{ $plat.os }}-{{ $plat.arch }}
---
kind: pipeline
type: kubernetes
name: publish-{{ $plat.os }}-{{ $plat.arch }}
trigger:
event: [ promote ]
target: [ publish, "publish-{{ $plat.os }}-{{ $plat.arch }}" ]
steps:
- name: build-and-publish
image: plugins/docker
settings:
registry: https://gitea.internal.example.com
username: drone
password:
from_secret: gitea-internal-password
repo: gitea.internal.example.com/{{ $.input.repo }}
cache_from: gitea.internal.example.com/{{ $.input.repo }}:ci-{{ $plat.os }}-{{ $plat.arch }}
build_args:
- OS={{ $plat.os }}
- ARCH={{ $plat.arch }}
{{ range $.input.build_args }}
- {{ . }}
{{ end }}
tags:
- latest-{{ $plat.os }}-{{ $plat.arch }}
{{ range $.input.tags }}
- {{ . }}-{{ $plat.os }}-{{ $plat.arch }}
{{ end }}
{{ end }}
---
kind: pipeline
type: kubernetes
name: publish-multiarch-manifest
trigger:
event: [ promote ]
target: [ publish ]
steps:
- name: deploy
image: gitea.internal.example.com/examples/docker:{{ if .input.docker_image_tag }}{{ .input.docker_image_tag }}{{ else }}latest{{ end }}
volumes:
- name: dockersock
path: /var/run/
environment:
DOCKER_REGISTRY: https://gitea.internal.example.com
DOCKER_USER: drone
DOCKER_PASS:
from_secret: gitea-internal-password
commands:
- /bin/docker-setup
- |
docker manifest create \
gitea.internal.example.com/{{ .input.repo }}:latest \
{{ range .input.platforms -}}
--amend gitea.internal.example.com/{{ $.input.repo }}:latest-{{ .os }}-{{ .arch }} \
{{- end }}
- docker manifest push gitea.internal.example.com/{{ .input.repo }}:latest
{{ range $i, $tag := $.input.tags }}
- |
docker manifest create \
gitea.internal.example.com/{{ $.input.repo }}:{{ $tag }} \
{{ range $.input.platforms -}}
gitea.internal.example.com/{{ $.input.repo }}:{{ $tag }}-{{ .os }}-{{ .arch }} \
{{- end }}
- docker manifest push gitea.internal.example.com/{{ $.input.repo }}:{{ $tag }}
{{ end }}
volumes:
- name: dockersock
host:
path: /var/run/
depends_on:
{{ range .input.platforms }}
- publish-{{ .os }}-{{ .arch }}
{{ end }}