mirror of
https://github.com/thegeeklab/drone-docker-buildx.git
synced 2024-06-29 21:50:54 +02:00
Compare commits
No commits in common. "main" and "v20.10.8" have entirely different histories.
|
@ -6,9 +6,13 @@
|
||||||
{{ range .CommitGroups -}}
|
{{ range .CommitGroups -}}
|
||||||
### {{ .Title }}
|
### {{ .Title }}
|
||||||
|
|
||||||
|
{{ $subjects := list }}
|
||||||
{{ range .Commits -}}
|
{{ range .Commits -}}
|
||||||
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ (regexReplaceAll "(.*)/issues/(.*)" (regexReplaceAll "(Co-\\w*-by.*)" .Subject "") "${1}/pull/${2}") | trim }}
|
{{ if not (has .Subject $subjects) -}}
|
||||||
|
- {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
|
||||||
|
{{ $subjects = append $subjects .Subject -}}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
{{- end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- if .NoteGroups -}}
|
{{- if .NoteGroups -}}
|
||||||
|
|
20
.dictionary
20
.dictionary
|
@ -1,20 +0,0 @@
|
||||||
url
|
|
||||||
ip
|
|
||||||
mtu
|
|
||||||
dns
|
|
||||||
ipv6
|
|
||||||
buildkit
|
|
||||||
json
|
|
||||||
config
|
|
||||||
dockerfile
|
|
||||||
og
|
|
||||||
gzip
|
|
||||||
toml
|
|
||||||
config
|
|
||||||
host:ip
|
|
||||||
drone-docker-buildx
|
|
||||||
multiarch
|
|
||||||
buildx
|
|
||||||
DockerHub
|
|
||||||
ECR
|
|
||||||
GHCR
|
|
339
.drone.jsonnet
Normal file
339
.drone.jsonnet
Normal file
|
@ -0,0 +1,339 @@
|
||||||
|
local PipelineTest = {
|
||||||
|
kind: 'pipeline',
|
||||||
|
image_pull_secrets: ['docker_config'],
|
||||||
|
name: 'test',
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'amd64',
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'staticcheck',
|
||||||
|
image: 'golang:1.16',
|
||||||
|
commands: [
|
||||||
|
'go run honnef.co/go/tools/cmd/staticcheck ./...',
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
path: '/go',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'lint',
|
||||||
|
image: 'golang:1.16',
|
||||||
|
commands: [
|
||||||
|
'go run golang.org/x/lint/golint -set_exit_status ./...',
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
path: '/go',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'vet',
|
||||||
|
image: 'golang:1.16',
|
||||||
|
commands: [
|
||||||
|
'go vet ./...',
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
path: '/go',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'test',
|
||||||
|
image: 'golang:1.16',
|
||||||
|
commands: [
|
||||||
|
'go test -cover ./...',
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
path: '/go',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: 'gopath',
|
||||||
|
temp: {},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
local PipelineBuildBinaries = {
|
||||||
|
kind: 'pipeline',
|
||||||
|
image_pull_secrets: ['docker_config'],
|
||||||
|
name: 'build-binaries',
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'amd64',
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'build',
|
||||||
|
image: 'techknowlogick/xgo:go-1.16.x',
|
||||||
|
commands: [
|
||||||
|
'[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}',
|
||||||
|
'mkdir -p release/',
|
||||||
|
"cd cmd/drone-docker-buildx && xgo -ldflags \"-s -w -X main.version=$BUILD_VERSION\" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm-7,linux/arm64' -out drone-docker-buildx .",
|
||||||
|
'mv /build/* /drone/src/release/',
|
||||||
|
'ls -l /drone/src/release/',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'executable',
|
||||||
|
image: 'alpine',
|
||||||
|
commands: [
|
||||||
|
'$(find release/ -executable -type f | grep drone-docker-buildx-linux-amd64) --help',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'compress',
|
||||||
|
image: 'alpine',
|
||||||
|
commands: [
|
||||||
|
'apk add upx',
|
||||||
|
'find release/ -maxdepth 1 -executable -type f -exec upx {} \\;',
|
||||||
|
'ls -lh release/',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'checksum',
|
||||||
|
image: 'alpine',
|
||||||
|
commands: [
|
||||||
|
'cd release/ && sha256sum * > sha256sum.txt',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'changelog-generate',
|
||||||
|
image: 'thegeeklab/git-chglog',
|
||||||
|
commands: [
|
||||||
|
'git fetch -tq',
|
||||||
|
'git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'changelog-format',
|
||||||
|
image: 'thegeeklab/alpine-tools',
|
||||||
|
commands: [
|
||||||
|
'prettier CHANGELOG.md',
|
||||||
|
'prettier -w CHANGELOG.md',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'publish',
|
||||||
|
image: 'plugins/github-release',
|
||||||
|
settings: {
|
||||||
|
overwrite: true,
|
||||||
|
api_key: {
|
||||||
|
from_secret: 'github_token',
|
||||||
|
},
|
||||||
|
files: ['release/*'],
|
||||||
|
title: '${DRONE_TAG}',
|
||||||
|
note: 'CHANGELOG.md',
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
ref: [
|
||||||
|
'refs/tags/**',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
'test',
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
local PipelineBuildContainer(arch='amd64') = {
|
||||||
|
kind: 'pipeline',
|
||||||
|
image_pull_secrets: ['docker_config'],
|
||||||
|
name: 'build-container-' + arch,
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: arch,
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
name: 'build',
|
||||||
|
image: 'golang:1.16',
|
||||||
|
commands: [
|
||||||
|
'[ -z "${DRONE_TAG}" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}',
|
||||||
|
'go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/' + arch + '/drone-docker-buildx ./cmd/drone-docker-buildx',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'dryrun',
|
||||||
|
image: 'plugins/docker:19',
|
||||||
|
settings: {
|
||||||
|
config: { from_secret: 'docker_config' },
|
||||||
|
dry_run: true,
|
||||||
|
dockerfile: 'docker/Dockerfile.' + arch,
|
||||||
|
repo: 'thegeeklab/${DRONE_REPO_NAME}',
|
||||||
|
username: { from_secret: 'docker_username' },
|
||||||
|
password: { from_secret: 'docker_password' },
|
||||||
|
},
|
||||||
|
depends_on: ['build'],
|
||||||
|
when: {
|
||||||
|
ref: ['refs/pull/**'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'publish-dockerhub',
|
||||||
|
image: 'plugins/docker:19',
|
||||||
|
settings: {
|
||||||
|
config: { from_secret: 'docker_config' },
|
||||||
|
auto_tag: true,
|
||||||
|
auto_tag_suffix: arch,
|
||||||
|
dockerfile: 'docker/Dockerfile.' + arch,
|
||||||
|
repo: 'thegeeklab/${DRONE_REPO_NAME}',
|
||||||
|
username: { from_secret: 'docker_username' },
|
||||||
|
password: { from_secret: 'docker_password' },
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**'],
|
||||||
|
},
|
||||||
|
depends_on: ['dryrun'],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'publish-quay',
|
||||||
|
image: 'plugins/docker:19',
|
||||||
|
settings: {
|
||||||
|
config: { from_secret: 'docker_config' },
|
||||||
|
auto_tag: true,
|
||||||
|
auto_tag_suffix: arch,
|
||||||
|
dockerfile: 'docker/Dockerfile.' + arch,
|
||||||
|
registry: 'quay.io',
|
||||||
|
repo: 'quay.io/thegeeklab/${DRONE_REPO_NAME}',
|
||||||
|
username: { from_secret: 'quay_username' },
|
||||||
|
password: { from_secret: 'quay_password' },
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**'],
|
||||||
|
},
|
||||||
|
depends_on: ['dryrun'],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
'test',
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**', 'refs/pull/**'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
local PipelineNotifications = {
|
||||||
|
kind: 'pipeline',
|
||||||
|
image_pull_secrets: ['docker_config'],
|
||||||
|
name: 'notifications',
|
||||||
|
platform: {
|
||||||
|
os: 'linux',
|
||||||
|
arch: 'amd64',
|
||||||
|
},
|
||||||
|
steps: [
|
||||||
|
{
|
||||||
|
image: 'plugins/manifest',
|
||||||
|
name: 'manifest-dockerhub',
|
||||||
|
settings: {
|
||||||
|
ignore_missing: true,
|
||||||
|
auto_tag: true,
|
||||||
|
username: { from_secret: 'docker_username' },
|
||||||
|
password: { from_secret: 'docker_password' },
|
||||||
|
spec: 'docker/manifest.tmpl',
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
status: ['success'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
image: 'plugins/manifest',
|
||||||
|
name: 'manifest-quay',
|
||||||
|
settings: {
|
||||||
|
ignore_missing: true,
|
||||||
|
auto_tag: true,
|
||||||
|
username: { from_secret: 'quay_username' },
|
||||||
|
password: { from_secret: 'quay_password' },
|
||||||
|
spec: 'docker/manifest-quay.tmpl',
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
status: ['success'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pushrm-dockerhub',
|
||||||
|
image: 'chko/docker-pushrm:1',
|
||||||
|
environment: {
|
||||||
|
DOCKER_PASS: {
|
||||||
|
from_secret: 'docker_password',
|
||||||
|
},
|
||||||
|
DOCKER_USER: {
|
||||||
|
from_secret: 'docker_username',
|
||||||
|
},
|
||||||
|
PUSHRM_FILE: 'README.md',
|
||||||
|
PUSHRM_SHORT: 'Drone plugin to build multiarch Docker images with buildx',
|
||||||
|
PUSHRM_TARGET: 'thegeeklab/${DRONE_REPO_NAME}',
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
status: ['success'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'pushrm-quay',
|
||||||
|
image: 'chko/docker-pushrm:1',
|
||||||
|
environment: {
|
||||||
|
APIKEY__QUAY_IO: {
|
||||||
|
from_secret: 'quay_token',
|
||||||
|
},
|
||||||
|
PUSHRM_FILE: 'README.md',
|
||||||
|
PUSHRM_TARGET: 'quay.io/thegeeklab/${DRONE_REPO_NAME}',
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
status: ['success'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'matrix',
|
||||||
|
image: 'plugins/matrix',
|
||||||
|
settings: {
|
||||||
|
homeserver: { from_secret: 'matrix_homeserver' },
|
||||||
|
roomid: { from_secret: 'matrix_roomid' },
|
||||||
|
template: 'Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}',
|
||||||
|
username: { from_secret: 'matrix_username' },
|
||||||
|
password: { from_secret: 'matrix_password' },
|
||||||
|
},
|
||||||
|
when: {
|
||||||
|
status: ['success', 'failure'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
depends_on: [
|
||||||
|
'build-binaries',
|
||||||
|
'build-container-amd64',
|
||||||
|
'build-container-arm64',
|
||||||
|
],
|
||||||
|
trigger: {
|
||||||
|
ref: ['refs/heads/main', 'refs/tags/**'],
|
||||||
|
status: ['success', 'failure'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
[
|
||||||
|
PipelineTest,
|
||||||
|
PipelineBuildBinaries,
|
||||||
|
PipelineBuildContainer(arch='amd64'),
|
||||||
|
PipelineBuildContainer(arch='arm64'),
|
||||||
|
PipelineNotifications,
|
||||||
|
]
|
399
.drone.yml
Normal file
399
.drone.yml
Normal file
|
@ -0,0 +1,399 @@
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: test
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: staticcheck
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- go run honnef.co/go/tools/cmd/staticcheck ./...
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
- name: lint
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- go run golang.org/x/lint/golint -set_exit_status ./...
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
- name: vet
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- go vet ./...
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
- name: test
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- go test -cover ./...
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
path: /go
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: gopath
|
||||||
|
temp: {}
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- docker_config
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
- refs/pull/**
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: build-binaries
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: techknowlogick/xgo:go-1.16.x
|
||||||
|
commands:
|
||||||
|
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
|
||||||
|
- mkdir -p release/
|
||||||
|
- cd cmd/drone-docker-buildx && xgo -ldflags "-s -w -X main.version=$BUILD_VERSION" -tags netgo -targets 'linux/amd64,linux/arm-6,linux/arm-7,linux/arm64' -out drone-docker-buildx .
|
||||||
|
- mv /build/* /drone/src/release/
|
||||||
|
- ls -l /drone/src/release/
|
||||||
|
|
||||||
|
- name: executable
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- $(find release/ -executable -type f | grep drone-docker-buildx-linux-amd64) --help
|
||||||
|
|
||||||
|
- name: compress
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- apk add upx
|
||||||
|
- find release/ -maxdepth 1 -executable -type f -exec upx {} \;
|
||||||
|
- ls -lh release/
|
||||||
|
|
||||||
|
- name: checksum
|
||||||
|
image: alpine
|
||||||
|
commands:
|
||||||
|
- cd release/ && sha256sum * > sha256sum.txt
|
||||||
|
|
||||||
|
- name: changelog-generate
|
||||||
|
image: thegeeklab/git-chglog
|
||||||
|
commands:
|
||||||
|
- git fetch -tq
|
||||||
|
- git-chglog --no-color --no-emoji -o CHANGELOG.md ${DRONE_TAG:---next-tag unreleased unreleased}
|
||||||
|
|
||||||
|
- name: changelog-format
|
||||||
|
image: thegeeklab/alpine-tools
|
||||||
|
commands:
|
||||||
|
- prettier CHANGELOG.md
|
||||||
|
- prettier -w CHANGELOG.md
|
||||||
|
|
||||||
|
- name: publish
|
||||||
|
image: plugins/github-release
|
||||||
|
settings:
|
||||||
|
api_key:
|
||||||
|
from_secret: github_token
|
||||||
|
files:
|
||||||
|
- release/*
|
||||||
|
note: CHANGELOG.md
|
||||||
|
overwrite: true
|
||||||
|
title: ${DRONE_TAG}
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/tags/**
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- docker_config
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
- refs/pull/**
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- test
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: build-container-amd64
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
|
||||||
|
- go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/amd64/drone-docker-buildx ./cmd/drone-docker-buildx
|
||||||
|
|
||||||
|
- name: dryrun
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.amd64
|
||||||
|
dry_run: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/pull/**
|
||||||
|
depends_on:
|
||||||
|
- build
|
||||||
|
|
||||||
|
- name: publish-dockerhub
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: amd64
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.amd64
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
depends_on:
|
||||||
|
- dryrun
|
||||||
|
|
||||||
|
- name: publish-quay
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: amd64
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.amd64
|
||||||
|
password:
|
||||||
|
from_secret: quay_password
|
||||||
|
registry: quay.io
|
||||||
|
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: quay_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
depends_on:
|
||||||
|
- dryrun
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- docker_config
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
- refs/pull/**
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- test
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: build-container-arm64
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: arm64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: build
|
||||||
|
image: golang:1.16
|
||||||
|
commands:
|
||||||
|
- "[ -z \"${DRONE_TAG}\" ] && BUILD_VERSION=${DRONE_COMMIT_SHA:0:8} || BUILD_VERSION=${DRONE_TAG##v}"
|
||||||
|
- go build -v -ldflags "-X main.version=$BUILD_VERSION" -a -tags netgo -o release/arm64/drone-docker-buildx ./cmd/drone-docker-buildx
|
||||||
|
|
||||||
|
- name: dryrun
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.arm64
|
||||||
|
dry_run: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/pull/**
|
||||||
|
depends_on:
|
||||||
|
- build
|
||||||
|
|
||||||
|
- name: publish-dockerhub
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: arm64
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.arm64
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
repo: thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
depends_on:
|
||||||
|
- dryrun
|
||||||
|
|
||||||
|
- name: publish-quay
|
||||||
|
image: plugins/docker:19
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
auto_tag_suffix: arm64
|
||||||
|
config:
|
||||||
|
from_secret: docker_config
|
||||||
|
dockerfile: docker/Dockerfile.arm64
|
||||||
|
password:
|
||||||
|
from_secret: quay_password
|
||||||
|
registry: quay.io
|
||||||
|
repo: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
username:
|
||||||
|
from_secret: quay_username
|
||||||
|
when:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
depends_on:
|
||||||
|
- dryrun
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- docker_config
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
- refs/pull/**
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- test
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: pipeline
|
||||||
|
name: notifications
|
||||||
|
|
||||||
|
platform:
|
||||||
|
os: linux
|
||||||
|
arch: amd64
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: manifest-dockerhub
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: docker_password
|
||||||
|
spec: docker/manifest.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: docker_username
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
|
||||||
|
- name: manifest-quay
|
||||||
|
image: plugins/manifest
|
||||||
|
settings:
|
||||||
|
auto_tag: true
|
||||||
|
ignore_missing: true
|
||||||
|
password:
|
||||||
|
from_secret: quay_password
|
||||||
|
spec: docker/manifest-quay.tmpl
|
||||||
|
username:
|
||||||
|
from_secret: quay_username
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
|
||||||
|
- name: pushrm-dockerhub
|
||||||
|
image: chko/docker-pushrm:1
|
||||||
|
environment:
|
||||||
|
DOCKER_PASS:
|
||||||
|
from_secret: docker_password
|
||||||
|
DOCKER_USER:
|
||||||
|
from_secret: docker_username
|
||||||
|
PUSHRM_FILE: README.md
|
||||||
|
PUSHRM_SHORT: Drone plugin to build multiarch Docker images with buildx
|
||||||
|
PUSHRM_TARGET: thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
|
||||||
|
- name: pushrm-quay
|
||||||
|
image: chko/docker-pushrm:1
|
||||||
|
environment:
|
||||||
|
APIKEY__QUAY_IO:
|
||||||
|
from_secret: quay_token
|
||||||
|
PUSHRM_FILE: README.md
|
||||||
|
PUSHRM_TARGET: quay.io/thegeeklab/${DRONE_REPO_NAME}
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
|
||||||
|
- name: matrix
|
||||||
|
image: plugins/matrix
|
||||||
|
settings:
|
||||||
|
homeserver:
|
||||||
|
from_secret: matrix_homeserver
|
||||||
|
password:
|
||||||
|
from_secret: matrix_password
|
||||||
|
roomid:
|
||||||
|
from_secret: matrix_roomid
|
||||||
|
template: "Status: **{{ build.status }}**<br/> Build: [{{ repo.Owner }}/{{ repo.Name }}]({{ build.link }}) ({{ build.branch }}) by {{ build.author }}<br/> Message: {{ build.message }}"
|
||||||
|
username:
|
||||||
|
from_secret: matrix_username
|
||||||
|
when:
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
- failure
|
||||||
|
|
||||||
|
image_pull_secrets:
|
||||||
|
- docker_config
|
||||||
|
|
||||||
|
trigger:
|
||||||
|
ref:
|
||||||
|
- refs/heads/main
|
||||||
|
- refs/tags/**
|
||||||
|
status:
|
||||||
|
- success
|
||||||
|
- failure
|
||||||
|
|
||||||
|
depends_on:
|
||||||
|
- build-binaries
|
||||||
|
- build-container-amd64
|
||||||
|
- build-container-arm64
|
||||||
|
|
||||||
|
---
|
||||||
|
kind: signature
|
||||||
|
hmac: d9ed315db5e0514b6151de65d4281802fad0882c5f71feff2f27a5686a794356
|
||||||
|
|
||||||
|
...
|
15
.github/settings.yml
vendored
15
.github/settings.yml
vendored
|
@ -1,7 +1,6 @@
|
||||||
repository:
|
repository:
|
||||||
name: drone-docker-buildx
|
name: drone-docker-buildx
|
||||||
description: Drone plugin to build multiarch Docker images with buildx
|
description: Drone plugin to build multiarch Docker images with buildx
|
||||||
homepage: https://drone-plugin-index.geekdocs.de/plugins/drone-docker-buildx
|
|
||||||
topics: drone, drone-plugin
|
topics: drone, drone-plugin
|
||||||
|
|
||||||
private: false
|
private: false
|
||||||
|
@ -52,17 +51,5 @@ branches:
|
||||||
strict: false
|
strict: false
|
||||||
contexts:
|
contexts:
|
||||||
- continuous-integration/drone/pr
|
- continuous-integration/drone/pr
|
||||||
enforce_admins: true
|
enforce_admins: null
|
||||||
required_linear_history: true
|
|
||||||
restrictions: null
|
restrictions: null
|
||||||
- name: docs
|
|
||||||
protection:
|
|
||||||
required_pull_request_reviews: null
|
|
||||||
required_status_checks: null
|
|
||||||
enforce_admins: true
|
|
||||||
required_linear_history: true
|
|
||||||
restrictions:
|
|
||||||
apps: []
|
|
||||||
users: []
|
|
||||||
teams:
|
|
||||||
- bot
|
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,4 +1,3 @@
|
||||||
/dist/
|
|
||||||
/release/
|
/release/
|
||||||
/drone-docker-buildx*
|
/drone-docker-buildx*
|
||||||
|
|
||||||
|
|
|
@ -1,97 +0,0 @@
|
||||||
linters:
|
|
||||||
enable-all: false
|
|
||||||
disable-all: true
|
|
||||||
enable:
|
|
||||||
- errcheck
|
|
||||||
- gosimple
|
|
||||||
- govet
|
|
||||||
- ineffassign
|
|
||||||
- staticcheck
|
|
||||||
- typecheck
|
|
||||||
- unused
|
|
||||||
- asasalint
|
|
||||||
- asciicheck
|
|
||||||
- bidichk
|
|
||||||
- bodyclose
|
|
||||||
- containedctx
|
|
||||||
- contextcheck
|
|
||||||
- decorder
|
|
||||||
- dogsled
|
|
||||||
- dupl
|
|
||||||
- dupword
|
|
||||||
- durationcheck
|
|
||||||
- errchkjson
|
|
||||||
- errname
|
|
||||||
- errorlint
|
|
||||||
- execinquery
|
|
||||||
- exhaustive
|
|
||||||
- exportloopref
|
|
||||||
- forcetypeassert
|
|
||||||
- ginkgolinter
|
|
||||||
- gocheckcompilerdirectives
|
|
||||||
- gochecknoglobals
|
|
||||||
- gochecknoinits
|
|
||||||
- gocognit
|
|
||||||
- goconst
|
|
||||||
- gocritic
|
|
||||||
- gocyclo
|
|
||||||
- godot
|
|
||||||
- godox
|
|
||||||
- goerr113
|
|
||||||
- gofmt
|
|
||||||
- gofumpt
|
|
||||||
- goheader
|
|
||||||
- goimports
|
|
||||||
- gomnd
|
|
||||||
- gomoddirectives
|
|
||||||
- gomodguard
|
|
||||||
- goprintffuncname
|
|
||||||
- gosec
|
|
||||||
- grouper
|
|
||||||
- importas
|
|
||||||
- interfacebloat
|
|
||||||
- ireturn
|
|
||||||
- lll
|
|
||||||
- loggercheck
|
|
||||||
- maintidx
|
|
||||||
- makezero
|
|
||||||
- misspell
|
|
||||||
- musttag
|
|
||||||
- nakedret
|
|
||||||
- nestif
|
|
||||||
- nilerr
|
|
||||||
- nilnil
|
|
||||||
- nlreturn
|
|
||||||
- noctx
|
|
||||||
- nolintlint
|
|
||||||
- nonamedreturns
|
|
||||||
- nosprintfhostport
|
|
||||||
- prealloc
|
|
||||||
- predeclared
|
|
||||||
- promlinter
|
|
||||||
- reassign
|
|
||||||
- revive
|
|
||||||
# - rowserrcheck
|
|
||||||
# - sqlclosecheck
|
|
||||||
# - structcheck
|
|
||||||
- stylecheck
|
|
||||||
- tagliatelle
|
|
||||||
- tenv
|
|
||||||
- testableexamples
|
|
||||||
- thelper
|
|
||||||
- tparallel
|
|
||||||
- unconvert
|
|
||||||
- unparam
|
|
||||||
- usestdlibvars
|
|
||||||
# - wastedassign
|
|
||||||
- whitespace
|
|
||||||
- wsl
|
|
||||||
fast: false
|
|
||||||
|
|
||||||
run:
|
|
||||||
timeout: 3m
|
|
||||||
|
|
||||||
linters-settings:
|
|
||||||
gofumpt:
|
|
||||||
extra-rules: true
|
|
||||||
lang-version: "1.20"
|
|
|
@ -1,6 +0,0 @@
|
||||||
---
|
|
||||||
default: True
|
|
||||||
MD013: False
|
|
||||||
MD041: False
|
|
||||||
MD004:
|
|
||||||
style: dash
|
|
|
@ -1,3 +1,2 @@
|
||||||
.drone.yml
|
.drone.yml
|
||||||
*.tpl.md
|
*.tpl.md
|
||||||
LICENSE
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
## Security
|
## Security
|
||||||
|
|
||||||
If you think you have found a **security issue**, please do not mention it in this repository.
|
If you think you have found a **security issue**, please do not mention it in this repository.
|
||||||
Instead, send an email to `security@thegeeklab.de` with as many details as possible so it can be handled confidential.
|
Instead, send an email to security@thegeeklab.de with as many details as possible so it can be handled confidential.
|
||||||
|
|
||||||
## Bug Reports and Feature Requests
|
## Bug Reports and Feature Requests
|
||||||
|
|
||||||
|
|
2
LICENSE
2
LICENSE
|
@ -187,7 +187,7 @@
|
||||||
same "printed page" as the copyright notice for easier
|
same "printed page" as the copyright notice for easier
|
||||||
identification within third-party archives.
|
identification within third-party archives.
|
||||||
|
|
||||||
Copyright 2022 Robert Kaussow <mail@thegeeklab.de>
|
Copyright 2021 Robert Kaussow <mail@thegeeklab.de>
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
|
101
Makefile
101
Makefile
|
@ -1,101 +0,0 @@
|
||||||
# renovate: datasource=github-releases depName=mvdan/gofumpt
|
|
||||||
GOFUMPT_PACKAGE_VERSION := v0.5.0
|
|
||||||
# renovate: datasource=github-releases depName=golangci/golangci-lint
|
|
||||||
GOLANGCI_LINT_PACKAGE_VERSION := v1.54.2
|
|
||||||
|
|
||||||
EXECUTABLE := drone-docker-buildx
|
|
||||||
|
|
||||||
DIST := dist
|
|
||||||
DIST_DIRS := $(DIST)
|
|
||||||
IMPORT := github.com/thegeeklab/$(EXECUTABLE)
|
|
||||||
|
|
||||||
GO ?= go
|
|
||||||
CWD ?= $(shell pwd)
|
|
||||||
PACKAGES ?= $(shell go list ./...)
|
|
||||||
SOURCES ?= $(shell find . -name "*.go" -type f)
|
|
||||||
|
|
||||||
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@$(GOFUMPT_PACKAGE_VERSION)
|
|
||||||
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_PACKAGE_VERSION)
|
|
||||||
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
|
|
||||||
|
|
||||||
GENERATE ?=
|
|
||||||
XGO_VERSION := go-1.20.x
|
|
||||||
XGO_TARGETS ?= linux/amd64,linux/arm64
|
|
||||||
|
|
||||||
TARGETOS ?= linux
|
|
||||||
TARGETARCH ?= amd64
|
|
||||||
ifneq ("$(TARGETVARIANT)","")
|
|
||||||
GOARM ?= $(subst v,,$(TARGETVARIANT))
|
|
||||||
endif
|
|
||||||
TAGS ?= netgo
|
|
||||||
|
|
||||||
ifndef VERSION
|
|
||||||
ifneq ($(DRONE_TAG),)
|
|
||||||
VERSION ?= $(subst v,,$(DRONE_TAG))
|
|
||||||
else
|
|
||||||
VERSION ?= $(shell git rev-parse --short HEAD)
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifndef DATE
|
|
||||||
DATE := $(shell date -u +"%Y-%m-%dT%H:%M:%S%z")
|
|
||||||
endif
|
|
||||||
|
|
||||||
LDFLAGS += -s -w -X "main.BuildVersion=$(VERSION)" -X "main.BuildDate=$(DATE)"
|
|
||||||
|
|
||||||
.PHONY: all
|
|
||||||
all: clean build
|
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
|
||||||
$(GO) clean -i ./...
|
|
||||||
rm -rf $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: fmt
|
|
||||||
fmt:
|
|
||||||
$(GO) run $(GOFUMPT_PACKAGE) -extra -w $(SOURCES)
|
|
||||||
|
|
||||||
.PHONY: golangci-lint
|
|
||||||
golangci-lint:
|
|
||||||
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
|
|
||||||
|
|
||||||
.PHONY: lint
|
|
||||||
lint: golangci-lint
|
|
||||||
|
|
||||||
.PHONY: generate
|
|
||||||
generate:
|
|
||||||
$(GO) generate $(GENERATE)
|
|
||||||
|
|
||||||
.PHONY: test
|
|
||||||
test:
|
|
||||||
$(GO) test -v -coverprofile coverage.out $(PACKAGES)
|
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build: $(DIST)/$(EXECUTABLE)
|
|
||||||
|
|
||||||
$(DIST)/$(EXECUTABLE): $(SOURCES)
|
|
||||||
GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) GOARM=$(GOARM) $(GO) build -v -tags '$(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -o $@ ./cmd/$(EXECUTABLE)
|
|
||||||
|
|
||||||
$(DIST_DIRS):
|
|
||||||
mkdir -p $(DIST_DIRS)
|
|
||||||
|
|
||||||
.PHONY: xgo
|
|
||||||
xgo: | $(DIST_DIRS)
|
|
||||||
$(GO) run $(XGO_PACKAGE) -go $(XGO_VERSION) -v -ldflags '-extldflags "-static" $(LDFLAGS)' -tags '$(TAGS)' -targets '$(XGO_TARGETS)' -out $(EXECUTABLE) --pkg cmd/$(EXECUTABLE) .
|
|
||||||
cp /build/* $(CWD)/$(DIST)
|
|
||||||
ls -l $(CWD)/$(DIST)
|
|
||||||
|
|
||||||
.PHONY: checksum
|
|
||||||
checksum:
|
|
||||||
cd $(DIST); $(foreach file,$(wildcard $(DIST)/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
|
||||||
ls -l $(CWD)/$(DIST)
|
|
||||||
|
|
||||||
.PHONY: release
|
|
||||||
release: xgo checksum
|
|
||||||
|
|
||||||
.PHONY: deps
|
|
||||||
deps:
|
|
||||||
$(GO) mod download
|
|
||||||
$(GO) install $(GOFUMPT_PACKAGE)
|
|
||||||
$(GO) install $(GOLANGCI_LINT_PACKAGE)
|
|
||||||
$(GO) install $(XGO_PACKAGE)
|
|
49
README.md
49
README.md
|
@ -1,6 +1,6 @@
|
||||||
# drone-docker-buildx
|
# drone-docker-buildx
|
||||||
|
|
||||||
DISCONTINUED: Drone plugin to build multiarch Docker images with buildx
|
Drone plugin to build multiarch Docker images with buildx
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-docker-buildx?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-docker-buildx)
|
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-docker-buildx?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-docker-buildx)
|
||||||
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-docker-buildx)
|
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-docker-buildx)
|
||||||
|
@ -8,15 +8,47 @@ DISCONTINUED: Drone plugin to build multiarch Docker images with buildx
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/drone-docker-buildx)](https://goreportcard.com/report/github.com/thegeeklab/drone-docker-buildx)
|
[![Go Report Card](https://goreportcard.com/badge/github.com/thegeeklab/drone-docker-buildx)](https://goreportcard.com/report/github.com/thegeeklab/drone-docker-buildx)
|
||||||
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/graphs/contributors)
|
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/graphs/contributors)
|
||||||
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-docker-buildx)
|
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-docker-buildx)
|
||||||
[![License: Apache-2.0](https://img.shields.io/github/license/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/blob/main/LICENSE)
|
[![License: MIT](https://img.shields.io/github/license/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/blob/main/LICENSE)
|
||||||
|
|
||||||
> **DISCONTINUED:** As I don't use Drone CI anymore, this project is unmaintained. If you are interested in a free and open source CI system check out [Woodpecker CI](https://woodpecker-ci.org/).
|
Drone plugin to build multiarch Docker images with buildx. This plugin is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker).
|
||||||
|
|
||||||
Drone plugin to build multiarch Docker images with buildx. This plugin is a fork of [drone-plugins/drone-docker](https://github.com/drone-plugins/drone-docker). You can find the full documentation at [https://drone-plugin-index.geekdocs.de](https://drone-plugin-index.geekdocs.de/plugins/drone-docker-buildx).
|
## Docker Tags
|
||||||
|
|
||||||
## Versioning
|
Tags are following the main Docker version e.g. `20.10`, the second part is reflecting the plugin "version". A full example would be `20.10.5`.
|
||||||
|
|
||||||
The tags follow the major version of Docker, e.g. `20`, and the minor and patch parts reflect the `version` of the plugin. A full example would be `20.12.5`. Minor versions can introduce breaking changes, while patch versions can be considered non-breaking.
|
## Build
|
||||||
|
|
||||||
|
Build the binary with the following command:
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
export GOOS=linux
|
||||||
|
export GOARCH=amd64
|
||||||
|
export CGO_ENABLED=0
|
||||||
|
export GO111MODULE=on
|
||||||
|
|
||||||
|
go build -v -a -tags netgo -o release/drone-docker-buildx
|
||||||
|
```
|
||||||
|
|
||||||
|
Build the Docker image with the following command:
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
docker build --file docker/Dockerfile.amd64 --tag thegeeklab/drone-docker-buildx .
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
> Notice: Be aware that the tis plugin requires privileged capabilities, otherwise the integrated Docker daemon is not able to start.
|
||||||
|
|
||||||
|
```console
|
||||||
|
docker run --rm \
|
||||||
|
-e PLUGIN_TAG=latest \
|
||||||
|
-e PLUGIN_REPO=octocat/hello-world \
|
||||||
|
-e DRONE_COMMIT_SHA=00000000 \
|
||||||
|
-v $(pwd):$(pwd) \
|
||||||
|
-w $(pwd) \
|
||||||
|
--privileged \
|
||||||
|
thegeeklab/drone-docker-buildx --dry-run
|
||||||
|
```
|
||||||
|
|
||||||
## Community
|
## Community
|
||||||
|
|
||||||
|
@ -30,8 +62,9 @@ The tags follow the major version of Docker, e.g. `20`, and the minor and patch
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
Special thanks to all [contributors](https://github.com/thegeeklab/drone-docker-buildx/graphs/contributors). If you would like to contribute, please see the [instructions](https://github.com/thegeeklab/drone-docker-buildx/blob/main/CONTRIBUTING.md).
|
Special thanks goes to all [contributors](https://github.com/thegeeklab/drone-docker-buildx/graphs/contributors). If you would like to contribute,
|
||||||
|
please see the [instructions](https://github.com/thegeeklab/drone-docker-buildx/blob/main/CONTRIBUTING.md).
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
This project is licensed under the Apache-2.0 License - see the [LICENSE](https://github.com/thegeeklab/drone-docker-buildx/blob/main/LICENSE) file for details.
|
This project is licensed under the MIT License - see the [LICENSE](https://github.com/thegeeklab/drone-docker-buildx/blob/main/LICENSE) file for details.
|
||||||
|
|
|
@ -1,128 +0,0 @@
|
||||||
---
|
|
||||||
title: drone-docker-buildx
|
|
||||||
---
|
|
||||||
|
|
||||||
[![Build Status](https://img.shields.io/drone/build/thegeeklab/drone-docker-buildx?logo=drone&server=https%3A%2F%2Fdrone.thegeeklab.de)](https://drone.thegeeklab.de/thegeeklab/drone-docker-buildx)
|
|
||||||
[![Docker Hub](https://img.shields.io/badge/dockerhub-latest-blue.svg?logo=docker&logoColor=white)](https://hub.docker.com/r/thegeeklab/drone-docker-buildx)
|
|
||||||
[![Quay.io](https://img.shields.io/badge/quay-latest-blue.svg?logo=docker&logoColor=white)](https://quay.io/repository/thegeeklab/drone-docker-buildx)
|
|
||||||
[![GitHub contributors](https://img.shields.io/github/contributors/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/graphs/contributors)
|
|
||||||
[![Source: GitHub](https://img.shields.io/badge/source-github-blue.svg?logo=github&logoColor=white)](https://github.com/thegeeklab/drone-docker-buildx)
|
|
||||||
[![License: MIT](https://img.shields.io/github/license/thegeeklab/drone-docker-buildx)](https://github.com/thegeeklab/drone-docker-buildx/blob/main/LICENSE)
|
|
||||||
|
|
||||||
Drone plugin to build and publish multiarch Docker images with buildx.
|
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< toc >}}
|
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
||||||
## Versioning
|
|
||||||
|
|
||||||
The tags follow the major version of Docker, e.g. `20`, and the minor and patch parts reflect the `version` of the plugin. A full example would be `20.12.5`. Minor versions can introduce breaking changes, while patch versions can be considered non-breaking.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
{{< hint type=important >}}
|
|
||||||
Be aware that the this plugin requires [privileged](https://docs.drone.io/pipeline/docker/syntax/steps/#privileged-mode) capabilities, otherwise the integrated Docker daemon is not able to start.
|
|
||||||
{{< /hint >}}
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: docker
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
privileged: true
|
|
||||||
settings:
|
|
||||||
username: octocat
|
|
||||||
password: secure
|
|
||||||
repo: octocat/example
|
|
||||||
tags: latest
|
|
||||||
```
|
|
||||||
|
|
||||||
### Parameters
|
|
||||||
|
|
||||||
<!-- prettier-ignore-start -->
|
|
||||||
<!-- spellchecker-disable -->
|
|
||||||
{{< propertylist name=drone-docker-buildx.data sort=name >}}
|
|
||||||
<!-- spellchecker-enable -->
|
|
||||||
<!-- prettier-ignore-end -->
|
|
||||||
|
|
||||||
### Examples
|
|
||||||
|
|
||||||
#### Push to other registries than DockerHub
|
|
||||||
|
|
||||||
If the created image is to be pushed to registries other than the default DockerHub, it is necessary to set `registry` and `repo` as fully-qualified name.
|
|
||||||
|
|
||||||
**GHCR:**
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: docker
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
privileged: true
|
|
||||||
settings:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: octocat
|
|
||||||
password: secret-access-token
|
|
||||||
repo: ghcr.io/octocat/example
|
|
||||||
tags: latest
|
|
||||||
```
|
|
||||||
|
|
||||||
**AWS ECR:**
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
kind: pipeline
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: docker
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
privileged: true
|
|
||||||
environment:
|
|
||||||
AWS_ACCESS_KEY_ID:
|
|
||||||
from_secret: aws_access_key_id
|
|
||||||
AWS_SECRET_ACCESS_KEY:
|
|
||||||
from_secret: aws_secret_access_key
|
|
||||||
settings:
|
|
||||||
registry: <account_id>.dkr.ecr.<region>.amazonaws.com
|
|
||||||
repo: <account_id>.dkr.ecr.<region>.amazonaws.com/octocat/example
|
|
||||||
tags: latest
|
|
||||||
```
|
|
||||||
|
|
||||||
## Build
|
|
||||||
|
|
||||||
Build the binary with the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
export GOOS=linux
|
|
||||||
export GOARCH=amd64
|
|
||||||
export CGO_ENABLED=0
|
|
||||||
export GO111MODULE=on
|
|
||||||
|
|
||||||
make build
|
|
||||||
```
|
|
||||||
|
|
||||||
Build the Docker image with the following command:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker build --file docker/Dockerfile.amd64 --tag thegeeklab/drone-docker-buildx .
|
|
||||||
```
|
|
||||||
|
|
||||||
## Test
|
|
||||||
|
|
||||||
```shell
|
|
||||||
docker run --rm \
|
|
||||||
-e PLUGIN_TAG=latest \
|
|
||||||
-e PLUGIN_REPO=octocat/hello-world \
|
|
||||||
-e DRONE_COMMIT_SHA=00000000 \
|
|
||||||
-v $(pwd):$(pwd) \
|
|
||||||
-w $(pwd) \
|
|
||||||
--privileged \
|
|
||||||
thegeeklab/drone-docker-buildx --dry-run
|
|
||||||
```
|
|
|
@ -1,295 +0,0 @@
|
||||||
---
|
|
||||||
properties:
|
|
||||||
- name: dry_run
|
|
||||||
description: Disable docker push.
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: mirror
|
|
||||||
description: Use a registry mirror to pull images.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: storage_driver
|
|
||||||
description: The docker daemon storage driver.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: storage_path
|
|
||||||
description: The docker daemon storage path.
|
|
||||||
defaultValue: /var/lib/docker
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: bip
|
|
||||||
description: Allows the docker daemon to bride IP address.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: mtu
|
|
||||||
description: A docker daemon custom MTU.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: custom_dns
|
|
||||||
description: Custom docker daemon DNS server.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: custom_dns_search
|
|
||||||
description: Custom docker daemon DNS search domain.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: insecure
|
|
||||||
description: Enable the usage of insecure registries.
|
|
||||||
type: bool
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: ipv6
|
|
||||||
description: Enable docker daemon IPv6 support.
|
|
||||||
type: bool
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: experimental
|
|
||||||
description: Enable docker daemon experimental mode.
|
|
||||||
type: bool
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: debug
|
|
||||||
description: Enable verbose debug mode for the docker daemon.
|
|
||||||
type: string
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: daemon_off
|
|
||||||
description: Disable the startup of the docker daemon.
|
|
||||||
type: string
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: buildkit_config
|
|
||||||
description: |
|
|
||||||
Content of the docker buildkit toml [config](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md). Example:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- name: Build
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
settings:
|
|
||||||
repo: example/repo
|
|
||||||
buildkit_config: |
|
|
||||||
[registry."registry.local:30081"]
|
|
||||||
http = true
|
|
||||||
insecure = true
|
|
||||||
```
|
|
||||||
type: string
|
|
||||||
defaultValue: false
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: dockerfile
|
|
||||||
description: Set dockerfile to use for the image build.
|
|
||||||
defaultValue: Dockerfile
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: context
|
|
||||||
description: Set the path of the build context to use.
|
|
||||||
defaultValue: .
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: named_context
|
|
||||||
description: Set additional named [build contexts](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context) (e.g., name=path).
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: tags
|
|
||||||
description: Set repository tags to use for the image. Tags can also be loaded from a `.tags` file.
|
|
||||||
defaultValue: latest
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: auto_tag
|
|
||||||
description: |
|
|
||||||
Generate tag names automatically based on git branch and git tag. When this feature is enabled and the event type is `tag`,
|
|
||||||
the plugin will automatically tag the image using the standard semVer convention. For example:
|
|
||||||
- `1.0.0` produces docker tags `1`, `1.0`, `1.0.0`
|
|
||||||
- `1.0.0-rc.1` produces docker tags `1.0.0-rc.1`
|
|
||||||
When the event type is `push` and the target branch is your default branch, the plugin will automatically tag the image
|
|
||||||
as `latest`. All other event types and branches are ignored.
|
|
||||||
defaultValue: false
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: auto_tag_suffix
|
|
||||||
description: Generate tag names with the given suffix.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: extra_tags
|
|
||||||
description: |
|
|
||||||
Set additional tags to be used for the image. Additional tags can also be loaded from an `.extratags` file. This function can be used
|
|
||||||
to push images to multiple registries at once. Therefore, it is necessary to use the `config` flag to provide a configuration file
|
|
||||||
that contains the authentication information for all used registries.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: build_args
|
|
||||||
description: Custom build arguments to pass to the build.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: build_args_from_env
|
|
||||||
description: Forward environment variables as custom arguments to the build.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: quiet
|
|
||||||
description: Enable suppression of the build output.
|
|
||||||
defaultValue: false
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: target
|
|
||||||
description: The docker build target.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: cache_from
|
|
||||||
description: |
|
|
||||||
Images to consider as [cache sources](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-from). To properly work,
|
|
||||||
commas used in the cache source entries need to be escaped:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- name: Build
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
settings:
|
|
||||||
repo: example/repo
|
|
||||||
cache_from:
|
|
||||||
# while using quotes, double-escaping is required
|
|
||||||
- "type=registry\\\\,ref=example"
|
|
||||||
- 'type=foo\\,ref=bar'
|
|
||||||
```
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: cache_to
|
|
||||||
description: |
|
|
||||||
[Cache destination](https://docs.docker.com/engine/reference/commandline/buildx_build/#cache-to) for the build cache.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: pull_image
|
|
||||||
description: Enforce to pull the base image at build time.
|
|
||||||
defaultValue: true
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: compress
|
|
||||||
description: Enable compression of the build context using gzip.
|
|
||||||
defaultValue: false
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: output
|
|
||||||
description: |
|
|
||||||
[Export action](https://docs.docker.com/engine/reference/commandline/buildx_build/#output) for the build result
|
|
||||||
(format: `path` or `type=TYPE[,KEY=VALUE]`).
|
|
||||||
defaultValue: false
|
|
||||||
type: bool
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: repo
|
|
||||||
description: |
|
|
||||||
Repository name for the image. If the image is to be pushed to registries other than the default DockerHub,
|
|
||||||
it is necessary to set `repo` as fully-qualified name.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: registry
|
|
||||||
description: Docker registry to upload images.
|
|
||||||
defaultValue: https://index.docker.io/v1/
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: username
|
|
||||||
description: Username for authentication with the registry.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: password
|
|
||||||
description: Password for authentication with the registry.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: email
|
|
||||||
description: E-Mail address for authentication with the registry.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: config
|
|
||||||
description: Content of the docker daemon json config.
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: no_cache
|
|
||||||
description: Disable the usage of cached intermediate containers.
|
|
||||||
defaultValue: false
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: add_host
|
|
||||||
description: Additional `host:ip` mapping.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: platforms
|
|
||||||
description: Target platforms for build.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: labels
|
|
||||||
description: Labels to add to the image.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: provenance
|
|
||||||
description: Generate [provenance](https://docs.docker.com/build/attestations/slsa-provenance/) attestation for the build (shorthand for `--attest=type=provenance`).
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: sbom
|
|
||||||
description: Generate [sbom](https://docs.docker.com/build/attestations/sbom/) attestation for the build (shorthand for `--attest type=sbom`).
|
|
||||||
type: string
|
|
||||||
required: false
|
|
||||||
|
|
||||||
- name: secrets
|
|
||||||
description: |
|
|
||||||
Exposes [secrets](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret) to the build.
|
|
||||||
The secrets can be used by the build using `RUN --mount=type=secret` mount.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
steps:
|
|
||||||
- name: Build
|
|
||||||
image: thegeeklab/drone-docker-buildx:23
|
|
||||||
privileged: true
|
|
||||||
environment:
|
|
||||||
SECURE_TOKEN:
|
|
||||||
from_secret: secure_token
|
|
||||||
settings:
|
|
||||||
secrets:
|
|
||||||
# while using quotes, double-escaping is required
|
|
||||||
- "id=raw_file_secret\\\\,src=file.txt"
|
|
||||||
- 'id=other_raw_file_secret\\,src=other_file.txt'
|
|
||||||
- "id=SECRET_TOKEN"
|
|
||||||
```
|
|
||||||
|
|
||||||
To use secrets from files a [host volume](https://docs.drone.io/pipeline/docker/syntax/volumes/host/) is required.
|
|
||||||
This should be used with caution and avoided whenever possible.
|
|
||||||
type: list
|
|
||||||
required: false
|
|
|
@ -2,331 +2,241 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/thegeeklab/drone-docker-buildx/plugin"
|
"github.com/thegeeklab/drone-docker-buildx/plugin"
|
||||||
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// settingsFlags has the cli.Flags for the plugin.Settings.
|
// settingsFlags has the cli.Flags for the plugin.Settings.
|
||||||
//
|
func settingsFlags(settings *plugin.Settings) []cli.Flag {
|
||||||
//nolint:maintidx
|
|
||||||
func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
|
||||||
return []cli.Flag{
|
return []cli.Flag{
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "dry-run",
|
Name: "dry-run",
|
||||||
|
Usage: "dry run disables docker push",
|
||||||
EnvVars: []string{"PLUGIN_DRY_RUN"},
|
EnvVars: []string{"PLUGIN_DRY_RUN"},
|
||||||
Usage: "disable docker push",
|
|
||||||
Destination: &settings.Dryrun,
|
Destination: &settings.Dryrun,
|
||||||
Category: category,
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "remote.url",
|
||||||
|
Usage: "git remote url",
|
||||||
|
EnvVars: []string{"DRONE_REMOTE_URL"},
|
||||||
|
Destination: &settings.Build.Remote,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "daemon.mirror",
|
Name: "daemon.mirror",
|
||||||
|
Usage: "docker daemon registry mirror",
|
||||||
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
|
EnvVars: []string{"PLUGIN_MIRROR", "DOCKER_PLUGIN_MIRROR"},
|
||||||
Usage: "registry mirror to pull images",
|
|
||||||
Destination: &settings.Daemon.Mirror,
|
Destination: &settings.Daemon.Mirror,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "daemon.storage-driver",
|
Name: "daemon.storage-driver",
|
||||||
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
|
|
||||||
Usage: "docker daemon storage driver",
|
Usage: "docker daemon storage driver",
|
||||||
|
EnvVars: []string{"PLUGIN_STORAGE_DRIVER"},
|
||||||
Destination: &settings.Daemon.StorageDriver,
|
Destination: &settings.Daemon.StorageDriver,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "daemon.storage-path",
|
Name: "daemon.storage-path",
|
||||||
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
|
|
||||||
Usage: "docker daemon storage path",
|
Usage: "docker daemon storage path",
|
||||||
Value: "/var/lib/docker",
|
Value: "/var/lib/docker",
|
||||||
|
EnvVars: []string{"PLUGIN_STORAGE_PATH"},
|
||||||
Destination: &settings.Daemon.StoragePath,
|
Destination: &settings.Daemon.StoragePath,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "daemon.bip",
|
Name: "daemon.bip",
|
||||||
|
Usage: "docker daemon bride ip address",
|
||||||
EnvVars: []string{"PLUGIN_BIP"},
|
EnvVars: []string{"PLUGIN_BIP"},
|
||||||
Usage: "allow the docker daemon to bride ip address",
|
|
||||||
Destination: &settings.Daemon.Bip,
|
Destination: &settings.Daemon.Bip,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "daemon.mtu",
|
Name: "daemon.mtu",
|
||||||
EnvVars: []string{"PLUGIN_MTU"},
|
|
||||||
Usage: "docker daemon custom mtu setting",
|
Usage: "docker daemon custom mtu setting",
|
||||||
|
EnvVars: []string{"PLUGIN_MTU"},
|
||||||
Destination: &settings.Daemon.MTU,
|
Destination: &settings.Daemon.MTU,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "daemon.dns",
|
Name: "daemon.dns",
|
||||||
|
Usage: "docker daemon dns server",
|
||||||
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
|
EnvVars: []string{"PLUGIN_CUSTOM_DNS"},
|
||||||
Usage: "custom docker daemon dns server",
|
|
||||||
Destination: &settings.Daemon.DNS,
|
Destination: &settings.Daemon.DNS,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "daemon.dns-search",
|
Name: "daemon.dns-search",
|
||||||
|
Usage: "docker daemon dns search domains",
|
||||||
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
|
EnvVars: []string{"PLUGIN_CUSTOM_DNS_SEARCH"},
|
||||||
Usage: "custom docker daemon dns search domain",
|
|
||||||
Destination: &settings.Daemon.DNSSearch,
|
Destination: &settings.Daemon.DNSSearch,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "daemon.insecure",
|
Name: "daemon.insecure",
|
||||||
|
Usage: "docker daemon allows insecure registries",
|
||||||
EnvVars: []string{"PLUGIN_INSECURE"},
|
EnvVars: []string{"PLUGIN_INSECURE"},
|
||||||
Usage: "allow the docker daemon to use insecure registries",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Daemon.Insecure,
|
Destination: &settings.Daemon.Insecure,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "daemon.ipv6",
|
Name: "daemon.ipv6",
|
||||||
|
Usage: "docker daemon IPv6 networking",
|
||||||
EnvVars: []string{"PLUGIN_IPV6"},
|
EnvVars: []string{"PLUGIN_IPV6"},
|
||||||
Usage: "enable docker daemon IPv6 support",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Daemon.IPv6,
|
Destination: &settings.Daemon.IPv6,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "daemon.experimental",
|
Name: "daemon.experimental",
|
||||||
|
Usage: "docker daemon Experimental mode",
|
||||||
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
|
EnvVars: []string{"PLUGIN_EXPERIMENTAL"},
|
||||||
Usage: "enable docker daemon experimental mode",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Daemon.Experimental,
|
Destination: &settings.Daemon.Experimental,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "daemon.debug",
|
Name: "daemon.debug",
|
||||||
EnvVars: []string{"PLUGIN_DEBUG"},
|
Usage: "docker daemon executes in debug mode",
|
||||||
Usage: "enable verbose debug mode for the docker daemon",
|
EnvVars: []string{"PLUGIN_DEBUG", "DOCKER_LAUNCH_DEBUG"},
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Daemon.Debug,
|
Destination: &settings.Daemon.Debug,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "daemon.off",
|
Name: "daemon.off",
|
||||||
|
Usage: "don't start the docker daemon",
|
||||||
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
|
EnvVars: []string{"PLUGIN_DAEMON_OFF"},
|
||||||
Usage: "disable the startup of the docker daemon",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Daemon.Disabled,
|
Destination: &settings.Daemon.Disabled,
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "daemon.buildkit-config",
|
|
||||||
EnvVars: []string{"PLUGIN_BUILDKIT_CONFIG"},
|
|
||||||
Usage: "content of the docker buildkit toml config",
|
|
||||||
Destination: &settings.Daemon.BuildkitConfig,
|
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "dockerfile",
|
Name: "dockerfile",
|
||||||
EnvVars: []string{"PLUGIN_DOCKERFILE"},
|
Usage: "build dockerfile",
|
||||||
Usage: "dockerfile to use for the image build",
|
|
||||||
Value: "Dockerfile",
|
Value: "Dockerfile",
|
||||||
|
EnvVars: []string{"PLUGIN_DOCKERFILE"},
|
||||||
Destination: &settings.Build.Dockerfile,
|
Destination: &settings.Build.Dockerfile,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "context",
|
Name: "context",
|
||||||
EnvVars: []string{"PLUGIN_CONTEXT"},
|
Usage: "build context",
|
||||||
Usage: "path of the build context",
|
|
||||||
Value: ".",
|
Value: ".",
|
||||||
|
EnvVars: []string{"PLUGIN_CONTEXT"},
|
||||||
Destination: &settings.Build.Context,
|
Destination: &settings.Build.Context,
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "named-context",
|
|
||||||
EnvVars: []string{"PLUGIN_NAMED_CONTEXT"},
|
|
||||||
Usage: "additional named build context",
|
|
||||||
Destination: &settings.Build.NamedContext,
|
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "tags",
|
Name: "tags",
|
||||||
|
Usage: "build tags",
|
||||||
|
Value: cli.NewStringSlice([]string{"latest"}...),
|
||||||
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
|
EnvVars: []string{"PLUGIN_TAG", "PLUGIN_TAGS"},
|
||||||
Usage: "repository tags to use for the image",
|
|
||||||
FilePath: ".tags",
|
FilePath: ".tags",
|
||||||
Destination: &settings.Build.Tags,
|
Destination: &settings.Build.Tags,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "tags.auto",
|
Name: "tags.auto",
|
||||||
|
Usage: "default build tags",
|
||||||
EnvVars: []string{"PLUGIN_DEFAULT_TAGS", "PLUGIN_AUTO_TAG"},
|
EnvVars: []string{"PLUGIN_DEFAULT_TAGS", "PLUGIN_AUTO_TAG"},
|
||||||
Usage: "generate tag names automatically based on git branch and git tag",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Build.TagsAuto,
|
Destination: &settings.Build.TagsAuto,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "tags.suffix",
|
Name: "tags.suffix",
|
||||||
|
Usage: "default build tags with suffix",
|
||||||
EnvVars: []string{"PLUGIN_DEFAULT_SUFFIX", "PLUGIN_AUTO_TAG_SUFFIX"},
|
EnvVars: []string{"PLUGIN_DEFAULT_SUFFIX", "PLUGIN_AUTO_TAG_SUFFIX"},
|
||||||
Usage: "generate tag names with the given suffix",
|
|
||||||
Destination: &settings.Build.TagsSuffix,
|
Destination: &settings.Build.TagsSuffix,
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "extra.tags",
|
|
||||||
EnvVars: []string{"PLUGIN_EXTRA_TAGS"},
|
|
||||||
Usage: "additional tags to use for the image including registry",
|
|
||||||
FilePath: ".extratags",
|
|
||||||
Destination: &settings.Build.ExtraTags,
|
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "args",
|
Name: "args",
|
||||||
|
Usage: "build args",
|
||||||
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
EnvVars: []string{"PLUGIN_BUILD_ARGS"},
|
||||||
Usage: "custom build arguments for the build",
|
|
||||||
Destination: &settings.Build.Args,
|
Destination: &settings.Build.Args,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "args-from-env",
|
Name: "args-from-env",
|
||||||
|
Usage: "build args",
|
||||||
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
|
EnvVars: []string{"PLUGIN_BUILD_ARGS_FROM_ENV"},
|
||||||
Usage: "forward environment variables as custom arguments to the build",
|
|
||||||
Destination: &settings.Build.ArgsEnv,
|
Destination: &settings.Build.ArgsEnv,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "quiet",
|
Name: "quiet",
|
||||||
|
Usage: "quiet docker build",
|
||||||
EnvVars: []string{"PLUGIN_QUIET"},
|
EnvVars: []string{"PLUGIN_QUIET"},
|
||||||
Usage: "enable suppression of the build output",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Build.Quiet,
|
Destination: &settings.Build.Quiet,
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "output",
|
|
||||||
EnvVars: []string{"PLUGIN_OUTPUT"},
|
|
||||||
Usage: "export action for the build result",
|
|
||||||
Destination: &settings.Build.Output,
|
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "target",
|
Name: "target",
|
||||||
|
Usage: "build target",
|
||||||
EnvVars: []string{"PLUGIN_TARGET"},
|
EnvVars: []string{"PLUGIN_TARGET"},
|
||||||
Usage: "build target to use",
|
|
||||||
Destination: &settings.Build.Target,
|
Destination: &settings.Build.Target,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.GenericFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "cache-from",
|
Name: "cache-from",
|
||||||
EnvVars: []string{"PLUGIN_CACHE_FROM"},
|
Usage: "images to consider as cache sources",
|
||||||
Usage: "images to consider as cache sources",
|
EnvVars: []string{"PLUGIN_CACHE_FROM"},
|
||||||
Value: &drone.StringSliceFlag{},
|
Destination: &settings.Build.CacheFrom,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.BoolFlag{
|
||||||
Name: "cache-to",
|
Name: "squash",
|
||||||
EnvVars: []string{"PLUGIN_CACHE_TO"},
|
Usage: "squash the layers at build time",
|
||||||
Usage: "cache destination for the build cache",
|
EnvVars: []string{"PLUGIN_SQUASH"},
|
||||||
Destination: &settings.Build.CacheTo,
|
Destination: &settings.Build.Squash,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "pull-image",
|
Name: "pull-image",
|
||||||
|
Usage: "force pull base image at build time",
|
||||||
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
|
EnvVars: []string{"PLUGIN_PULL_IMAGE"},
|
||||||
Usage: "enforce to pull base image at build time",
|
|
||||||
Value: true,
|
Value: true,
|
||||||
Destination: &settings.Build.Pull,
|
Destination: &settings.Build.Pull,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "compress",
|
Name: "compress",
|
||||||
|
Usage: "compress the build context using gzip",
|
||||||
EnvVars: []string{"PLUGIN_COMPRESS"},
|
EnvVars: []string{"PLUGIN_COMPRESS"},
|
||||||
Usage: "enable compression of the build context using gzip",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Build.Compress,
|
Destination: &settings.Build.Compress,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "repo",
|
Name: "repo",
|
||||||
|
Usage: "docker repository",
|
||||||
EnvVars: []string{"PLUGIN_REPO"},
|
EnvVars: []string{"PLUGIN_REPO"},
|
||||||
Usage: "repository name for the image",
|
|
||||||
Destination: &settings.Build.Repo,
|
Destination: &settings.Build.Repo,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "docker.registry",
|
Name: "docker.registry",
|
||||||
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
|
Usage: "docker registry",
|
||||||
Usage: "docker registry to authenticate with",
|
|
||||||
Value: "https://index.docker.io/v1/",
|
Value: "https://index.docker.io/v1/",
|
||||||
|
EnvVars: []string{"PLUGIN_REGISTRY", "DOCKER_REGISTRY"},
|
||||||
Destination: &settings.Login.Registry,
|
Destination: &settings.Login.Registry,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "docker.username",
|
Name: "docker.username",
|
||||||
|
Usage: "docker username",
|
||||||
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
|
EnvVars: []string{"PLUGIN_USERNAME", "DOCKER_USERNAME"},
|
||||||
Usage: "username for registry authentication",
|
|
||||||
Destination: &settings.Login.Username,
|
Destination: &settings.Login.Username,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "docker.password",
|
Name: "docker.password",
|
||||||
|
Usage: "docker password",
|
||||||
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
|
EnvVars: []string{"PLUGIN_PASSWORD", "DOCKER_PASSWORD"},
|
||||||
Usage: "password for registry authentication",
|
|
||||||
Destination: &settings.Login.Password,
|
Destination: &settings.Login.Password,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "docker.email",
|
Name: "docker.email",
|
||||||
|
Usage: "docker email",
|
||||||
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
|
EnvVars: []string{"PLUGIN_EMAIL", "DOCKER_EMAIL"},
|
||||||
Usage: "email address for registry authentication",
|
|
||||||
Destination: &settings.Login.Email,
|
Destination: &settings.Login.Email,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "docker.config",
|
Name: "docker.config",
|
||||||
|
Usage: "docker json dockerconfig content",
|
||||||
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
|
EnvVars: []string{"PLUGIN_CONFIG", "DOCKER_PLUGIN_CONFIG"},
|
||||||
Usage: "content of the docker daemon json config",
|
|
||||||
Destination: &settings.Login.Config,
|
Destination: &settings.Login.Config,
|
||||||
Category: category,
|
},
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "docker.purge",
|
||||||
|
Usage: "docker should cleanup images",
|
||||||
|
EnvVars: []string{"PLUGIN_PURGE"},
|
||||||
|
Value: true,
|
||||||
|
Destination: &settings.Cleanup,
|
||||||
},
|
},
|
||||||
&cli.BoolFlag{
|
&cli.BoolFlag{
|
||||||
Name: "no-cache",
|
Name: "no-cache",
|
||||||
|
Usage: "do not use cached intermediate containers",
|
||||||
EnvVars: []string{"PLUGIN_NO_CACHE"},
|
EnvVars: []string{"PLUGIN_NO_CACHE"},
|
||||||
Usage: "disable the usage of cached intermediate containers",
|
|
||||||
Value: false,
|
|
||||||
Destination: &settings.Build.NoCache,
|
Destination: &settings.Build.NoCache,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "add-host",
|
Name: "add-host",
|
||||||
|
Usage: "additional host:IP mapping",
|
||||||
EnvVars: []string{"PLUGIN_ADD_HOST"},
|
EnvVars: []string{"PLUGIN_ADD_HOST"},
|
||||||
Usage: "additional host:ip mapping",
|
|
||||||
Destination: &settings.Build.AddHost,
|
Destination: &settings.Build.AddHost,
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
&cli.StringSliceFlag{
|
&cli.StringSliceFlag{
|
||||||
Name: "platforms",
|
Name: "platforms",
|
||||||
|
Usage: "arget platform for build",
|
||||||
EnvVars: []string{"PLUGIN_PLATFORMS"},
|
EnvVars: []string{"PLUGIN_PLATFORMS"},
|
||||||
Usage: "target platform for build",
|
|
||||||
Destination: &settings.Build.Platforms,
|
Destination: &settings.Build.Platforms,
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringSliceFlag{
|
|
||||||
Name: "labels",
|
|
||||||
EnvVars: []string{"PLUGIN_LABELS"},
|
|
||||||
Usage: "labels to add to image",
|
|
||||||
Destination: &settings.Build.Labels,
|
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "provenance",
|
|
||||||
EnvVars: []string{"PLUGIN_PROVENANCE"},
|
|
||||||
Usage: "generates provenance attestation for the build",
|
|
||||||
Destination: &settings.Build.Provenance,
|
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.StringFlag{
|
|
||||||
Name: "sbom",
|
|
||||||
EnvVars: []string{"PLUGIN_SBOM"},
|
|
||||||
Usage: "generates sbom attestation for the build",
|
|
||||||
Destination: &settings.Build.SBOM,
|
|
||||||
Category: category,
|
|
||||||
},
|
|
||||||
&cli.GenericFlag{
|
|
||||||
Name: "secrets",
|
|
||||||
EnvVars: []string{"PLUGIN_SECRETS"},
|
|
||||||
Usage: "exposes secrets to the build",
|
|
||||||
Value: &drone.StringSliceFlag{},
|
|
||||||
Category: category,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,48 +1,35 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/thegeeklab/drone-docker-buildx/plugin"
|
"github.com/thegeeklab/drone-docker-buildx/plugin"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
|
||||||
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
|
"github.com/drone-plugins/drone-plugin-lib/errors"
|
||||||
"github.com/thegeeklab/drone-plugin-lib/v2/urfave"
|
"github.com/drone-plugins/drone-plugin-lib/urfave"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:gochecknoglobals
|
var version = "unknown"
|
||||||
var (
|
|
||||||
BuildVersion = "devel"
|
|
||||||
BuildDate = "00000000"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ErrTypeAssertionFailed = errors.New("type assertion failed")
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
settings := &plugin.Settings{}
|
settings := &plugin.Settings{}
|
||||||
|
|
||||||
if _, err := os.Stat("/run/drone/env"); err == nil {
|
if _, err := os.Stat("/run/drone/env"); err == nil {
|
||||||
_ = godotenv.Overload("/run/drone/env")
|
godotenv.Overload("/run/drone/env")
|
||||||
}
|
|
||||||
|
|
||||||
cli.VersionPrinter = func(c *cli.Context) {
|
|
||||||
fmt.Printf("%s version=%s date=%s\n", c.App.Name, c.App.Version, BuildDate)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app := &cli.App{
|
app := &cli.App{
|
||||||
Name: "drone-docker-buildx",
|
Name: "drone-docker-buildx",
|
||||||
Usage: "build docker container with DinD and buildx",
|
Usage: "build docker container with DinD and buildx",
|
||||||
Version: BuildVersion,
|
Version: version,
|
||||||
Flags: append(settingsFlags(settings, urfave.FlagsPluginCategory), urfave.Flags()...),
|
Flags: append(settingsFlags(settings), urfave.Flags()...),
|
||||||
Action: run(settings),
|
Action: run(settings),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := app.Run(os.Args); err != nil {
|
if err := app.Run(os.Args); err != nil {
|
||||||
logrus.Fatal(err)
|
errors.HandleExit(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,20 +37,6 @@ func run(settings *plugin.Settings) cli.ActionFunc {
|
||||||
return func(ctx *cli.Context) error {
|
return func(ctx *cli.Context) error {
|
||||||
urfave.LoggingFromContext(ctx)
|
urfave.LoggingFromContext(ctx)
|
||||||
|
|
||||||
cacheFrom, ok := ctx.Generic("cache-from").(*drone.StringSliceFlag)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("%w: failed to read cache-from input", ErrTypeAssertionFailed)
|
|
||||||
}
|
|
||||||
|
|
||||||
settings.Build.CacheFrom = cacheFrom.Get()
|
|
||||||
|
|
||||||
secrets, ok := ctx.Generic("secrets").(*drone.StringSliceFlag)
|
|
||||||
if !ok {
|
|
||||||
return fmt.Errorf("%w: failed to read secrets input", ErrTypeAssertionFailed)
|
|
||||||
}
|
|
||||||
|
|
||||||
settings.Build.Secrets = secrets.Get()
|
|
||||||
|
|
||||||
plugin := plugin.New(
|
plugin := plugin.New(
|
||||||
*settings,
|
*settings,
|
||||||
urfave.PipelineFromContext(ctx),
|
urfave.PipelineFromContext(ctx),
|
||||||
|
@ -71,11 +44,19 @@ func run(settings *plugin.Settings) cli.ActionFunc {
|
||||||
)
|
)
|
||||||
|
|
||||||
if err := plugin.Validate(); err != nil {
|
if err := plugin.Validate(); err != nil {
|
||||||
return fmt.Errorf("validation failed: %w", err)
|
if e, ok := err.(errors.ExitCoder); ok {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.ExitMessagef("validation failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := plugin.Execute(); err != nil {
|
if err := plugin.Execute(); err != nil {
|
||||||
return fmt.Errorf("execution failed: %w", err)
|
if e, ok := err.(errors.ExitCoder); ok {
|
||||||
|
return e
|
||||||
|
}
|
||||||
|
|
||||||
|
return errors.ExitMessagef("execution failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
8
cmd/drone-docker-buildx/tools.go
Normal file
8
cmd/drone-docker-buildx/tools.go
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// +build tools
|
||||||
|
|
||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
_ "golang.org/x/lint/golint"
|
||||||
|
_ "honnef.co/go/tools/cmd/staticcheck"
|
||||||
|
)
|
|
@ -1,14 +1,4 @@
|
||||||
FROM --platform=$BUILDPLATFORM golang:1.20@sha256:741d6f9bcab778441efe05c8e4369d4f8ff56c9a635a97d77f55d8b0ec62f907 as build
|
FROM amd64/docker:20.10-dind@sha256:331cba8b693454e3d71f78e0e4aa7341599431aa200c6f81c1e3cb023f1e0cc9
|
||||||
|
|
||||||
ARG TARGETOS
|
|
||||||
ARG TARGETARCH
|
|
||||||
|
|
||||||
ADD . /src
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
RUN make build
|
|
||||||
|
|
||||||
FROM docker:24.0-dind@sha256:020562d22f11c27997e00da910ed6b580d93094bc25841cb87aacab4ced4a882
|
|
||||||
|
|
||||||
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
|
@ -17,25 +7,21 @@ LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-docker-b
|
||||||
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-docker-buildx"
|
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-docker-buildx"
|
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
|
||||||
ARG TARGETOS
|
|
||||||
ARG TARGETARCH
|
|
||||||
ARG BUILDX_VERSION
|
ARG BUILDX_VERSION
|
||||||
|
|
||||||
# renovate: datasource=github-releases depName=docker/buildx
|
# renovate: datasource=github-releases depName=docker/buildx
|
||||||
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.11.2}"
|
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.5.1}"
|
||||||
|
|
||||||
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
||||||
|
|
||||||
RUN apk --update add --virtual .build-deps curl && \
|
RUN apk --update add --virtual .build-deps curl && \
|
||||||
apk --update add --no-cache git coredns && \
|
|
||||||
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
||||||
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx \
|
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.linux-amd64" && \
|
||||||
"https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.${TARGETOS:-linux}-${TARGETARCH:-amd64}" && \
|
|
||||||
chmod 755 /usr/lib/docker/cli-plugins/docker-buildx && \
|
chmod 755 /usr/lib/docker/cli-plugins/docker-buildx && \
|
||||||
apk del .build-deps && \
|
apk del .build-deps && \
|
||||||
rm -rf /var/cache/apk/* && \
|
rm -rf /var/cache/apk/* && \
|
||||||
rm -rf /tmp/*
|
rm -rf /tmp/*
|
||||||
|
|
||||||
COPY --from=build /src/Corefile /etc/coredns/Corefile
|
ADD release/amd64/drone-docker-buildx /bin/
|
||||||
COPY --from=build /src/dist/drone-docker-buildx /bin/drone-docker-buildx
|
|
||||||
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
27
docker/Dockerfile.arm
Normal file
27
docker/Dockerfile.arm
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
FROM arm32v7/docker:20.10-dind
|
||||||
|
|
||||||
|
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
|
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
|
LABEL org.opencontainers.image.title="drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
|
||||||
|
ARG BUILDX_VERSION
|
||||||
|
|
||||||
|
# renovate: datasource=github-releases depName=docker/buildx
|
||||||
|
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.5.1}"
|
||||||
|
|
||||||
|
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
||||||
|
|
||||||
|
RUN apk --update add --virtual .build-deps curl && \
|
||||||
|
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
||||||
|
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.linux-arm-v7" && \
|
||||||
|
chmod 755 /usr/lib/docker/cli-plugins/docker-buildx && \
|
||||||
|
apk del .build-deps && \
|
||||||
|
rm -rf /var/cache/apk/* && \
|
||||||
|
rm -rf /tmp/*
|
||||||
|
|
||||||
|
ADD release/arm/drone-docker-buildx /bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
27
docker/Dockerfile.arm64
Normal file
27
docker/Dockerfile.arm64
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
FROM arm64v8/docker:20.10-dind@sha256:270717ac4571bec14b3d54a81564b79aa683344ce7b6d5daf5ae162fbcb32fd4
|
||||||
|
|
||||||
|
LABEL maintainer="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
|
LABEL org.opencontainers.image.authors="Robert Kaussow <mail@thegeeklab.de>"
|
||||||
|
LABEL org.opencontainers.image.title="drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.url="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.source="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
LABEL org.opencontainers.image.documentation="https://github.com/thegeeklab/drone-docker-buildx"
|
||||||
|
|
||||||
|
ARG BUILDX_VERSION
|
||||||
|
|
||||||
|
# renovate: datasource=github-releases depName=docker/buildx
|
||||||
|
ENV BUILDX_VERSION="${BUILDX_VERSION:-v0.5.1}"
|
||||||
|
|
||||||
|
ENV DOCKER_HOST=unix:///var/run/docker.sock
|
||||||
|
|
||||||
|
RUN apk --update add --virtual .build-deps curl && \
|
||||||
|
mkdir -p /usr/lib/docker/cli-plugins/ && \
|
||||||
|
curl -SsL -o /usr/lib/docker/cli-plugins/docker-buildx "https://github.com/docker/buildx/releases/download/v${BUILDX_VERSION##v}/buildx-v${BUILDX_VERSION##v}.linux-arm64" && \
|
||||||
|
chmod 755 /usr/lib/docker/cli-plugins/docker-buildx && \
|
||||||
|
apk del .build-deps && \
|
||||||
|
rm -rf /var/cache/apk/* && \
|
||||||
|
rm -rf /tmp/*
|
||||||
|
|
||||||
|
ADD release/arm64/drone-docker-buildx /bin/
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "drone-docker-buildx"]
|
24
docker/manifest-quay.tmpl
Normal file
24
docker/manifest-quay.tmpl
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
image: quay.io/thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||||
|
{{#if build.tags}}
|
||||||
|
tags:
|
||||||
|
{{#each build.tags}}
|
||||||
|
- {{this}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
manifests:
|
||||||
|
- image: quay.io/thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
|
||||||
|
platform:
|
||||||
|
architecture: amd64
|
||||||
|
os: linux
|
||||||
|
|
||||||
|
- image: quay.io/thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
|
||||||
|
platform:
|
||||||
|
architecture: arm64
|
||||||
|
os: linux
|
||||||
|
variant: v8
|
||||||
|
|
||||||
|
- image: quay.io/thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
|
||||||
|
platform:
|
||||||
|
architecture: arm
|
||||||
|
os: linux
|
||||||
|
variant: v7
|
24
docker/manifest.tmpl
Normal file
24
docker/manifest.tmpl
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
image: thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||||
|
{{#if build.tags}}
|
||||||
|
tags:
|
||||||
|
{{#each build.tags}}
|
||||||
|
- {{this}}
|
||||||
|
{{/each}}
|
||||||
|
{{/if}}
|
||||||
|
manifests:
|
||||||
|
- image: thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}amd64
|
||||||
|
platform:
|
||||||
|
architecture: amd64
|
||||||
|
os: linux
|
||||||
|
|
||||||
|
- image: thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm64
|
||||||
|
platform:
|
||||||
|
architecture: arm64
|
||||||
|
os: linux
|
||||||
|
variant: v8
|
||||||
|
|
||||||
|
- image: thegeeklab/drone-docker-buildx:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}arm
|
||||||
|
platform:
|
||||||
|
architecture: arm
|
||||||
|
os: linux
|
||||||
|
variant: v7
|
23
go.mod
23
go.mod
|
@ -1,18 +1,17 @@
|
||||||
module github.com/thegeeklab/drone-docker-buildx
|
module github.com/thegeeklab/drone-docker-buildx
|
||||||
|
|
||||||
go 1.20
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/coreos/go-semver v0.3.1
|
github.com/coreos/go-semver v0.3.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.9.3
|
github.com/drone-plugins/drone-plugin-lib v0.4.0
|
||||||
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4
|
github.com/joho/godotenv v1.3.0
|
||||||
github.com/urfave/cli/v2 v2.25.5
|
|
||||||
golang.org/x/sys v0.11.0
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
|
github.com/sirupsen/logrus v1.8.1
|
||||||
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616
|
||||||
|
golang.org/x/mod v0.4.2 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 // indirect
|
||||||
|
honnef.co/go/tools v0.2.0
|
||||||
)
|
)
|
||||||
|
|
94
go.sum
94
go.sum
|
@ -1,31 +1,77 @@
|
||||||
github.com/coreos/go-semver v0.3.1 h1:yi21YpKnrx1gt5R+la8n5WgS0kCrsPp33dmEyHReZr4=
|
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||||
github.com/coreos/go-semver v0.3.1/go.mod h1:irMmmIw/7yzSRPWryHsK7EYSg09caPQL03VsM8rvUec=
|
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 h1:EoUDS0afbrsXAZ9YQ9jdu/mZ2sXgT1/2yyNng4PGlyM=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/drone-plugins/drone-plugin-lib v0.4.0 h1:qywEYGhquUuid6zNLmKia8CWY1TUa8jPQQ/G9ozfAmc=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/drone-plugins/drone-plugin-lib v0.4.0/go.mod h1:EgqogX38GoJFtckeSQyhBJYX8P+KWBPhdprAVvyRxF8=
|
||||||
|
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
|
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
|
||||||
|
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||||
|
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||||
|
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||||
|
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4 h1:Quzrike/xRAR0izxQ0d+ocJyIUm4h1497Oyo9grcRzg=
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
github.com/thegeeklab/drone-plugin-lib/v2 v2.3.4/go.mod h1:qWVUZCmwL0Ntwa/hvyqM03EeIr1ReBR2XJsmIc7MGus=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/urfave/cli/v2 v2.25.5 h1:d0NIAyhh5shGscroL7ek/Ya9QYQE0KNabJgiUinIQkc=
|
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
|
||||||
github.com/urfave/cli/v2 v2.25.5/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
|
github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
|
||||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
|
||||||
|
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
|
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||||
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||||
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
|
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096 h1:5PbJGn5Sp3GEUjJ61aYbUP6RIo3Z3r2E4Tv9y2z8UHo=
|
||||||
|
golang.org/x/sys v0.0.0-20210507161434-a76c4d0a0096/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
|
golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY=
|
||||||
|
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v2 v2.2.3 h1:fvjTMHxHEw/mxHbtzPi3JCcKXQRAnQTBRo6YCJSVHKI=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
|
||||||
|
honnef.co/go/tools v0.1.4 h1:SadWOkti5uVN1FAMgxn165+Mw00fuQKyk4Gyn/inxNQ=
|
||||||
|
honnef.co/go/tools v0.1.4/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
|
||||||
|
honnef.co/go/tools v0.2.0 h1:ws8AfbgTX3oIczLPNPCu5166oBg9ST2vNs0rcht+mDE=
|
||||||
|
honnef.co/go/tools v0.2.0/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY=
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
package plugin
|
|
||||||
|
|
||||||
import (
|
|
||||||
"io"
|
|
||||||
"net"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p Plugin) startCoredns() {
|
|
||||||
cmd := exec.Command("coredns", "-conf", "/etc/coredns/Corefile")
|
|
||||||
if p.settings.Daemon.Debug {
|
|
||||||
cmd.Stdout = os.Stdout
|
|
||||||
cmd.Stderr = os.Stderr
|
|
||||||
} else {
|
|
||||||
cmd.Stdout = io.Discard
|
|
||||||
cmd.Stderr = io.Discard
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
trace(cmd)
|
|
||||||
_ = cmd.Run()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
|
|
||||||
func getContainerIP() (string, error) {
|
|
||||||
netInterfaceAddrList, err := net.InterfaceAddrs()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, netInterfaceAddr := range netInterfaceAddrList {
|
|
||||||
netIP, ok := netInterfaceAddr.(*net.IPNet)
|
|
||||||
if ok && !netIP.IP.IsLoopback() && netIP.IP.To4() != nil {
|
|
||||||
return netIP.IP.String(), nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", nil
|
|
||||||
}
|
|
|
@ -1,16 +1,13 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const dockerExe = "/usr/local/bin/docker"
|
||||||
dockerBin = "/usr/local/bin/docker"
|
const dockerdExe = "/usr/local/bin/dockerd"
|
||||||
dockerdBin = "/usr/local/bin/dockerd"
|
const dockerHome = "/root/.docker/"
|
||||||
dockerHome = "/root/.docker/"
|
|
||||||
buildkitConfig = "/tmp/buildkit.toml"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (p Plugin) startDaemon() {
|
func (p Plugin) startDaemon() {
|
||||||
cmd := commandDaemon(p.settings.Daemon)
|
cmd := commandDaemon(p.settings.Daemon)
|
||||||
|
@ -18,12 +15,11 @@ func (p Plugin) startDaemon() {
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
} else {
|
} else {
|
||||||
cmd.Stdout = io.Discard
|
cmd.Stdout = ioutil.Discard
|
||||||
cmd.Stderr = io.Discard
|
cmd.Stderr = ioutil.Discard
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
trace(cmd)
|
trace(cmd)
|
||||||
_ = cmd.Run()
|
cmd.Run()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
131
plugin/docker.go
131
plugin/docker.go
|
@ -3,75 +3,65 @@ package plugin
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/sys/execabs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// helper function to create the docker login command.
|
// helper function to create the docker login command.
|
||||||
func commandLogin(login Login) *execabs.Cmd {
|
func commandLogin(login Login) *exec.Cmd {
|
||||||
if login.Email != "" {
|
if login.Email != "" {
|
||||||
return commandLoginEmail(login)
|
return commandLoginEmail(login)
|
||||||
}
|
}
|
||||||
|
return exec.Command(
|
||||||
args := []string{
|
dockerExe, "login",
|
||||||
"login",
|
|
||||||
"-u", login.Username,
|
"-u", login.Username,
|
||||||
"-p", login.Password,
|
"-p", login.Password,
|
||||||
login.Registry,
|
login.Registry,
|
||||||
}
|
|
||||||
|
|
||||||
return execabs.Command(
|
|
||||||
dockerBin, args...,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandLoginEmail(login Login) *execabs.Cmd {
|
// helper to check if args match "docker pull <image>"
|
||||||
args := []string{
|
func isCommandPull(args []string) bool {
|
||||||
"login",
|
return len(args) > 2 && args[1] == "pull"
|
||||||
|
}
|
||||||
|
|
||||||
|
func commandPull(repo string) *exec.Cmd {
|
||||||
|
return exec.Command(dockerExe, "pull", repo)
|
||||||
|
}
|
||||||
|
|
||||||
|
func commandLoginEmail(login Login) *exec.Cmd {
|
||||||
|
return exec.Command(
|
||||||
|
dockerExe, "login",
|
||||||
"-u", login.Username,
|
"-u", login.Username,
|
||||||
"-p", login.Password,
|
"-p", login.Password,
|
||||||
"-e", login.Email,
|
"-e", login.Email,
|
||||||
login.Registry,
|
login.Registry,
|
||||||
}
|
|
||||||
|
|
||||||
return execabs.Command(
|
|
||||||
dockerBin, args...,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker info command.
|
// helper function to create the docker info command.
|
||||||
func commandVersion() *execabs.Cmd {
|
func commandVersion() *exec.Cmd {
|
||||||
return execabs.Command(dockerBin, "version")
|
return exec.Command(dockerExe, "version")
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker info command.
|
// helper function to create the docker info command.
|
||||||
func commandInfo() *execabs.Cmd {
|
func commandInfo() *exec.Cmd {
|
||||||
return execabs.Command(dockerBin, "info")
|
return exec.Command(dockerExe, "info")
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandBuilder(daemon Daemon) *execabs.Cmd {
|
func commandBuilder() *exec.Cmd {
|
||||||
args := []string{
|
return exec.Command(dockerExe, "buildx", "create", "--use")
|
||||||
"buildx",
|
|
||||||
"create",
|
|
||||||
"--use",
|
|
||||||
}
|
|
||||||
|
|
||||||
if daemon.BuildkitConfig != "" {
|
|
||||||
args = append(args, "--config", buildkitConfig)
|
|
||||||
}
|
|
||||||
|
|
||||||
return execabs.Command(dockerBin, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func commandBuildx() *execabs.Cmd {
|
func commandBuildx() *exec.Cmd {
|
||||||
return execabs.Command(dockerBin, "buildx", "ls")
|
return exec.Command(dockerExe, "buildx", "ls")
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker build command.
|
// helper function to create the docker build command.
|
||||||
func commandBuild(build Build, dryrun bool) *execabs.Cmd {
|
func commandBuild(build Build, dryrun bool) *exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"buildx",
|
"buildx",
|
||||||
"build",
|
"build",
|
||||||
|
@ -84,90 +74,52 @@ func commandBuild(build Build, dryrun bool) *execabs.Cmd {
|
||||||
}
|
}
|
||||||
|
|
||||||
args = append(args, build.Context)
|
args = append(args, build.Context)
|
||||||
if !dryrun && build.Output == "" && len(build.Tags.Value()) > 0 {
|
if ! dryrun {
|
||||||
args = append(args, "--push")
|
args = append(args, "--push")
|
||||||
}
|
}
|
||||||
|
if build.Squash {
|
||||||
|
args = append(args, "--squash")
|
||||||
|
}
|
||||||
if build.Compress {
|
if build.Compress {
|
||||||
args = append(args, "--compress")
|
args = append(args, "--compress")
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Pull {
|
if build.Pull {
|
||||||
args = append(args, "--pull=true")
|
args = append(args, "--pull=true")
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.NoCache {
|
if build.NoCache {
|
||||||
args = append(args, "--no-cache")
|
args = append(args, "--no-cache")
|
||||||
}
|
}
|
||||||
|
for _, arg := range build.CacheFrom.Value() {
|
||||||
for _, arg := range build.CacheFrom {
|
|
||||||
args = append(args, "--cache-from", arg)
|
args = append(args, "--cache-from", arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.CacheTo != "" {
|
|
||||||
args = append(args, "--cache-to", build.CacheTo)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, arg := range build.ArgsEnv.Value() {
|
for _, arg := range build.ArgsEnv.Value() {
|
||||||
addProxyValue(&build, arg)
|
addProxyValue(&build, arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range append(defaultBuildArgs, build.Args.Value()...) {
|
for _, arg := range append(defaultBuildArgs, build.Args.Value()...) {
|
||||||
args = append(args, "--build-arg", arg)
|
args = append(args, "--build-arg", arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, host := range build.AddHost.Value() {
|
for _, host := range build.AddHost.Value() {
|
||||||
args = append(args, "--add-host", host)
|
args = append(args, "--add-host", host)
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Target != "" {
|
if build.Target != "" {
|
||||||
args = append(args, "--target", build.Target)
|
args = append(args, "--target", build.Target)
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Quiet {
|
if build.Quiet {
|
||||||
args = append(args, "--quiet")
|
args = append(args, "--quiet")
|
||||||
}
|
}
|
||||||
|
|
||||||
if build.Output != "" {
|
|
||||||
args = append(args, "--output", build.Output)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, arg := range build.NamedContext.Value() {
|
|
||||||
args = append(args, "--build-context", arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(build.Platforms.Value()) > 0 {
|
if len(build.Platforms.Value()) > 0 {
|
||||||
args = append(args, "--platform", strings.Join(build.Platforms.Value(), ","))
|
args = append(args, "--platform", strings.Join(build.Platforms.Value()[:], ","))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range build.Tags.Value() {
|
for _, arg := range build.Tags.Value() {
|
||||||
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
|
args = append(args, "-t", fmt.Sprintf("%s:%s", build.Repo, arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg := range build.ExtraTags.Value() {
|
return exec.Command(dockerExe, args...)
|
||||||
args = append(args, "-t", arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, arg := range build.Labels.Value() {
|
|
||||||
args = append(args, "--label", arg)
|
|
||||||
}
|
|
||||||
|
|
||||||
if build.Provenance != "" {
|
|
||||||
args = append(args, "--provenance", build.Provenance)
|
|
||||||
}
|
|
||||||
|
|
||||||
if build.SBOM != "" {
|
|
||||||
args = append(args, "--sbom", build.SBOM)
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, secret := range build.Secrets {
|
|
||||||
args = append(args, "--secret", secret)
|
|
||||||
}
|
|
||||||
|
|
||||||
return execabs.Command(dockerBin, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to add proxy values from the environment.
|
// helper function to add proxy values from the environment
|
||||||
func addProxyBuildArgs(build *Build) {
|
func addProxyBuildArgs(build *Build) {
|
||||||
addProxyValue(build, "http_proxy")
|
addProxyValue(build, "http_proxy")
|
||||||
addProxyValue(build, "https_proxy")
|
addProxyValue(build, "https_proxy")
|
||||||
|
@ -211,7 +163,7 @@ func hasProxyBuildArg(build *Build, key string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to create the docker daemon command.
|
// helper function to create the docker daemon command.
|
||||||
func commandDaemon(daemon Daemon) *execabs.Cmd {
|
func commandDaemon(daemon Daemon) *exec.Cmd {
|
||||||
args := []string{
|
args := []string{
|
||||||
"--data-root", daemon.StoragePath,
|
"--data-root", daemon.StoragePath,
|
||||||
"--host=unix:///var/run/docker.sock",
|
"--host=unix:///var/run/docker.sock",
|
||||||
|
@ -220,44 +172,35 @@ func commandDaemon(daemon Daemon) *execabs.Cmd {
|
||||||
if daemon.StorageDriver != "" {
|
if daemon.StorageDriver != "" {
|
||||||
args = append(args, "-s", daemon.StorageDriver)
|
args = append(args, "-s", daemon.StorageDriver)
|
||||||
}
|
}
|
||||||
|
|
||||||
if daemon.Insecure && daemon.Registry != "" {
|
if daemon.Insecure && daemon.Registry != "" {
|
||||||
args = append(args, "--insecure-registry", daemon.Registry)
|
args = append(args, "--insecure-registry", daemon.Registry)
|
||||||
}
|
}
|
||||||
|
|
||||||
if daemon.IPv6 {
|
if daemon.IPv6 {
|
||||||
args = append(args, "--ipv6")
|
args = append(args, "--ipv6")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(daemon.Mirror) != 0 {
|
if len(daemon.Mirror) != 0 {
|
||||||
args = append(args, "--registry-mirror", daemon.Mirror)
|
args = append(args, "--registry-mirror", daemon.Mirror)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(daemon.Bip) != 0 {
|
if len(daemon.Bip) != 0 {
|
||||||
args = append(args, "--bip", daemon.Bip)
|
args = append(args, "--bip", daemon.Bip)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dns := range daemon.DNS.Value() {
|
for _, dns := range daemon.DNS.Value() {
|
||||||
args = append(args, "--dns", dns)
|
args = append(args, "--dns", dns)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dnsSearch := range daemon.DNSSearch.Value() {
|
for _, dnsSearch := range daemon.DNSSearch.Value() {
|
||||||
args = append(args, "--dns-search", dnsSearch)
|
args = append(args, "--dns-search", dnsSearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(daemon.MTU) != 0 {
|
if len(daemon.MTU) != 0 {
|
||||||
args = append(args, "--mtu", daemon.MTU)
|
args = append(args, "--mtu", daemon.MTU)
|
||||||
}
|
}
|
||||||
|
|
||||||
if daemon.Experimental {
|
if daemon.Experimental {
|
||||||
args = append(args, "--experimental")
|
args = append(args, "--experimental")
|
||||||
}
|
}
|
||||||
|
return exec.Command(dockerdExe, args...)
|
||||||
return execabs.Command(dockerdBin, args...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace writes each command to stdout with the command wrapped in an xml
|
// trace writes each command to stdout with the command wrapped in an xml
|
||||||
// tag so that it can be extracted and displayed in the logs.
|
// tag so that it can be extracted and displayed in the logs.
|
||||||
func trace(cmd *execabs.Cmd) {
|
func trace(cmd *exec.Cmd) {
|
||||||
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
|
fmt.Fprintf(os.Stdout, "+ %s\n", strings.Join(cmd.Args, " "))
|
||||||
}
|
}
|
||||||
|
|
1
plugin/docker_test.go
Normal file
1
plugin/docker_test.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package plugin
|
159
plugin/impl.go
159
plugin/impl.go
|
@ -2,31 +2,31 @@ package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"golang.org/x/sys/execabs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Daemon defines Docker daemon parameters.
|
// Daemon defines Docker daemon parameters.
|
||||||
type Daemon struct {
|
type Daemon struct {
|
||||||
Registry string // Docker registry
|
Registry string // Docker registry
|
||||||
Mirror string // Docker registry mirror
|
Mirror string // Docker registry mirror
|
||||||
Insecure bool // Docker daemon enable insecure registries
|
Insecure bool // Docker daemon enable insecure registries
|
||||||
StorageDriver string // Docker daemon storage driver
|
StorageDriver string // Docker daemon storage driver
|
||||||
StoragePath string // Docker daemon storage path
|
StoragePath string // Docker daemon storage path
|
||||||
Disabled bool // DOcker daemon is disabled (already running)
|
Disabled bool // DOcker daemon is disabled (already running)
|
||||||
Debug bool // Docker daemon started in debug mode
|
Debug bool // Docker daemon started in debug mode
|
||||||
Bip string // Docker daemon network bridge IP address
|
Bip string // Docker daemon network bridge IP address
|
||||||
DNS cli.StringSlice // Docker daemon dns server
|
DNS cli.StringSlice // Docker daemon dns server
|
||||||
DNSSearch cli.StringSlice // Docker daemon dns search domain
|
DNSSearch cli.StringSlice // Docker daemon dns search domain
|
||||||
MTU string // Docker daemon mtu setting
|
MTU string // Docker daemon mtu setting
|
||||||
IPv6 bool // Docker daemon IPv6 networking
|
IPv6 bool // Docker daemon IPv6 networking
|
||||||
Experimental bool // Docker daemon enable experimental mode
|
Experimental bool // Docker daemon enable experimental mode
|
||||||
BuildkitConfig string // Docker buildkit config
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Login defines Docker login parameters.
|
// Login defines Docker login parameters.
|
||||||
|
@ -40,44 +40,37 @@ type Login struct {
|
||||||
|
|
||||||
// Build defines Docker build parameters.
|
// Build defines Docker build parameters.
|
||||||
type Build struct {
|
type Build struct {
|
||||||
Ref string // Git commit ref
|
Remote string // Git remote URL
|
||||||
Branch string // Git repository branch
|
Ref string // Git commit ref
|
||||||
Dockerfile string // Docker build Dockerfile
|
Branch string // Git repository branch
|
||||||
Context string // Docker build context
|
Dockerfile string // Docker build Dockerfile
|
||||||
TagsAuto bool // Docker build auto tag
|
Context string // Docker build context
|
||||||
TagsSuffix string // Docker build tags with suffix
|
TagsAuto bool // Docker build auto tag
|
||||||
Tags cli.StringSlice // Docker build tags
|
TagsSuffix string // Docker build tags with suffix
|
||||||
ExtraTags cli.StringSlice // Docker build tags including registry
|
Tags cli.StringSlice // Docker build tags
|
||||||
Platforms cli.StringSlice // Docker build target platforms
|
Platforms cli.StringSlice // Docker build target platforms
|
||||||
Args cli.StringSlice // Docker build args
|
Args cli.StringSlice // Docker build args
|
||||||
ArgsEnv cli.StringSlice // Docker build args from env
|
ArgsEnv cli.StringSlice // Docker build args from env
|
||||||
Target string // Docker build target
|
Target string // Docker build target
|
||||||
Pull bool // Docker build pull
|
Squash bool // Docker build squash
|
||||||
CacheFrom []string // Docker build cache-from
|
Pull bool // Docker build pull
|
||||||
CacheTo string // Docker build cache-to
|
CacheFrom cli.StringSlice // Docker build cache-from
|
||||||
Compress bool // Docker build compress
|
Compress bool // Docker build compress
|
||||||
Repo string // Docker build repository
|
Repo string // Docker build repository
|
||||||
NoCache bool // Docker build no-cache
|
NoCache bool // Docker build no-cache
|
||||||
AddHost cli.StringSlice // Docker build add-host
|
AddHost cli.StringSlice // Docker build add-host
|
||||||
Quiet bool // Docker build quiet
|
Quiet bool // Docker build quiet
|
||||||
Output string // Docker build output folder
|
|
||||||
NamedContext cli.StringSlice // Docker build named context
|
|
||||||
Labels cli.StringSlice // Docker build labels
|
|
||||||
Provenance string // Docker build provenance attestation
|
|
||||||
SBOM string // Docker build sbom attestation
|
|
||||||
Secrets []string // Docker build secrets
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Settings for the Plugin.
|
// Settings for the Plugin.
|
||||||
type Settings struct {
|
type Settings struct {
|
||||||
Daemon Daemon
|
Daemon Daemon
|
||||||
Login Login
|
Login Login
|
||||||
Build Build
|
Build Build
|
||||||
Dryrun bool
|
Dryrun bool
|
||||||
|
Cleanup bool
|
||||||
}
|
}
|
||||||
|
|
||||||
const strictFilePerm = 0o600
|
|
||||||
|
|
||||||
// Validate handles the settings validation of the plugin.
|
// Validate handles the settings validation of the plugin.
|
||||||
func (p *Plugin) Validate() error {
|
func (p *Plugin) Validate() error {
|
||||||
p.settings.Build.Branch = p.pipeline.Repo.Branch
|
p.settings.Build.Branch = p.pipeline.Repo.Branch
|
||||||
|
@ -95,15 +88,12 @@ func (p *Plugin) Validate() error {
|
||||||
p.settings.Build.TagsSuffix,
|
p.settings.Build.TagsSuffix,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infof("cannot generate tags from %s, invalid semantic version", p.settings.Build.Ref)
|
logrus.Printf("cannot build docker image for %s, invalid semantic version", p.settings.Build.Ref)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
|
p.settings.Build.Tags = *cli.NewStringSlice(tag...)
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("skip auto-tagging for %s, not on default branch or tag", p.settings.Build.Ref)
|
logrus.Printf("skipping automated docker build for %s", p.settings.Build.Ref)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,29 +102,9 @@ func (p *Plugin) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute provides the implementation of the plugin.
|
// Execute provides the implementation of the plugin.
|
||||||
//
|
|
||||||
//nolint:gocognit
|
|
||||||
func (p *Plugin) Execute() error {
|
func (p *Plugin) Execute() error {
|
||||||
// start the Docker daemon server
|
// start the Docker daemon server
|
||||||
//nolint: nestif
|
|
||||||
if !p.settings.Daemon.Disabled {
|
if !p.settings.Daemon.Disabled {
|
||||||
// If no custom DNS value set start internal DNS server
|
|
||||||
if len(p.settings.Daemon.DNS.Value()) == 0 {
|
|
||||||
ip, err := getContainerIP()
|
|
||||||
if err != nil {
|
|
||||||
logrus.Warnf("error detecting IP address: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if ip != "" {
|
|
||||||
logrus.Debugf("discovered IP address: %v", ip)
|
|
||||||
p.startCoredns()
|
|
||||||
|
|
||||||
if err := p.settings.Daemon.DNS.Set(ip); err != nil {
|
|
||||||
return fmt.Errorf("error setting daemon dns: %w", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
p.startDaemon()
|
p.startDaemon()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,64 +112,61 @@ func (p *Plugin) Execute() error {
|
||||||
// ready to accept connections before we proceed.
|
// ready to accept connections before we proceed.
|
||||||
for i := 0; i < 15; i++ {
|
for i := 0; i < 15; i++ {
|
||||||
cmd := commandInfo()
|
cmd := commandInfo()
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
time.Sleep(time.Second * 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create Auth Config File
|
// Create Auth Config File
|
||||||
if p.settings.Login.Config != "" {
|
if p.settings.Login.Config != "" {
|
||||||
if err := os.MkdirAll(dockerHome, strictFilePerm); err != nil {
|
os.MkdirAll(dockerHome, 0600)
|
||||||
return fmt.Errorf("failed to create docker home: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
path := filepath.Join(dockerHome, "config.json")
|
path := filepath.Join(dockerHome, "config.json")
|
||||||
|
err := ioutil.WriteFile(path, []byte(p.settings.Login.Config), 0600)
|
||||||
err := os.WriteFile(path, []byte(p.settings.Login.Config), strictFilePerm)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error writing config.json: %w", err)
|
return fmt.Errorf("error writing config.json: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// login to the Docker registry
|
// login to the Docker registry
|
||||||
if p.settings.Login.Password != "" {
|
if p.settings.Login.Password != "" {
|
||||||
cmd := commandLogin(p.settings.Login)
|
cmd := commandLogin(p.settings.Login)
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error authenticating: %w", err)
|
return fmt.Errorf("error authenticating: %s", err)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if p.settings.Daemon.BuildkitConfig != "" {
|
|
||||||
err := os.WriteFile(buildkitConfig, []byte(p.settings.Daemon.BuildkitConfig), strictFilePerm)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error writing buildkit.toml: %w", err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case p.settings.Login.Password != "":
|
case p.settings.Login.Password != "":
|
||||||
logrus.Info("Detected registry credentials")
|
fmt.Println("Detected registry credentials")
|
||||||
case p.settings.Login.Config != "":
|
case p.settings.Login.Config != "":
|
||||||
logrus.Info("Detected registry credentials file")
|
fmt.Println("Detected registry credentials file")
|
||||||
default:
|
default:
|
||||||
logrus.Info("Registry credentials or Docker config not provided. Guest mode enabled.")
|
fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.settings.Build.Squash && !p.settings.Daemon.Experimental {
|
||||||
|
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
|
||||||
|
p.settings.Build.Squash = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// add proxy build args
|
// add proxy build args
|
||||||
addProxyBuildArgs(&p.settings.Build)
|
addProxyBuildArgs(&p.settings.Build)
|
||||||
|
|
||||||
var cmds []*execabs.Cmd
|
var cmds []*exec.Cmd
|
||||||
cmds = append(cmds, commandVersion()) // docker version
|
cmds = append(cmds, commandVersion()) // docker version
|
||||||
cmds = append(cmds, commandInfo()) // docker info
|
cmds = append(cmds, commandInfo()) // docker info
|
||||||
cmds = append(cmds, commandBuilder(p.settings.Daemon))
|
cmds = append(cmds, commandBuilder())
|
||||||
cmds = append(cmds, commandBuildx())
|
cmds = append(cmds, commandBuildx())
|
||||||
|
|
||||||
|
// pre-pull cache images
|
||||||
|
for _, img := range p.settings.Build.CacheFrom.Value() {
|
||||||
|
cmds = append(cmds, commandPull(img))
|
||||||
|
}
|
||||||
|
|
||||||
cmds = append(cmds, commandBuild(p.settings.Build, p.settings.Dryrun)) // docker build
|
cmds = append(cmds, commandBuild(p.settings.Build, p.settings.Dryrun)) // docker build
|
||||||
|
|
||||||
// execute all commands in batch mode.
|
// execute all commands in batch mode.
|
||||||
|
@ -209,7 +176,9 @@ func (p *Plugin) Execute() error {
|
||||||
trace(cmd)
|
trace(cmd)
|
||||||
|
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err != nil {
|
if err != nil && isCommandPull(cmd.Args) {
|
||||||
|
fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
|
||||||
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package plugin
|
package plugin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/thegeeklab/drone-plugin-lib/v2/drone"
|
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Plugin implements drone.Plugin to provide the plugin implementation.
|
// Plugin implements drone.Plugin to provide the plugin implementation.
|
||||||
|
@ -12,7 +12,7 @@ type Plugin struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
// New initializes a plugin from the given Settings, Pipeline, and Network.
|
||||||
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) *Plugin {
|
func New(settings Settings, pipeline drone.Pipeline, network drone.Network) drone.Plugin {
|
||||||
return &Plugin{
|
return &Plugin{
|
||||||
settings: settings,
|
settings: settings,
|
||||||
pipeline: pipeline,
|
pipeline: pipeline,
|
||||||
|
|
|
@ -14,11 +14,9 @@ func DefaultTagSuffix(ref, suffix string) ([]string, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(suffix) == 0 {
|
if len(suffix) == 0 {
|
||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tag := range tags {
|
for i, tag := range tags {
|
||||||
if tag == "latest" {
|
if tag == "latest" {
|
||||||
tags[i] = suffix
|
tags[i] = suffix
|
||||||
|
@ -26,15 +24,13 @@ func DefaultTagSuffix(ref, suffix string) ([]string, error) {
|
||||||
tags[i] = fmt.Sprintf("%s-%s", tag, suffix)
|
tags[i] = fmt.Sprintf("%s-%s", tag, suffix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tags, nil
|
return tags, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func splitOff(input, delim string) string {
|
func splitOff(input string, delim string) string {
|
||||||
const splits = 2
|
parts := strings.SplitN(input, delim, 2)
|
||||||
parts := strings.SplitN(input, delim, splits)
|
|
||||||
|
|
||||||
if len(parts) == splits {
|
if len(parts) == 2 {
|
||||||
return parts[0]
|
return parts[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,65 +43,42 @@ func DefaultTags(ref string) ([]string, error) {
|
||||||
if !strings.HasPrefix(ref, "refs/tags/") {
|
if !strings.HasPrefix(ref, "refs/tags/") {
|
||||||
return []string{"latest"}, nil
|
return []string{"latest"}, nil
|
||||||
}
|
}
|
||||||
|
v := stripTagPrefix(ref)
|
||||||
rawVersion := stripTagPrefix(ref)
|
version, err := semver.NewVersion(v)
|
||||||
|
|
||||||
version, err := semver.NewVersion(rawVersion)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []string{"latest"}, err
|
return []string{"latest"}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if version.PreRelease != "" || version.Metadata != "" {
|
if version.PreRelease != "" || version.Metadata != "" {
|
||||||
return []string{
|
return []string{
|
||||||
version.String(),
|
version.String(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
rawVersion = stripTagPrefix(ref)
|
v = stripTagPrefix(ref)
|
||||||
rawVersion = splitOff(splitOff(rawVersion, "+"), "-")
|
v = splitOff(splitOff(v, "+"), "-")
|
||||||
//nolint:gomnd
|
dotParts := strings.SplitN(v, ".", 3)
|
||||||
dotParts := strings.SplitN(rawVersion, ".", 3)
|
|
||||||
|
|
||||||
if version.Major == 0 {
|
if version.Major == 0 {
|
||||||
return []string{
|
return []string{
|
||||||
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
|
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
|
||||||
fmt.Sprintf(
|
fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch),
|
||||||
"%0*d.%0*d.%0*d",
|
|
||||||
len(dotParts[0]),
|
|
||||||
version.Major,
|
|
||||||
len(dotParts[1]),
|
|
||||||
version.Minor,
|
|
||||||
len(dotParts[2]),
|
|
||||||
version.Patch,
|
|
||||||
),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return []string{
|
return []string{
|
||||||
fmt.Sprintf("%0*d", len(dotParts[0]), version.Major),
|
fmt.Sprintf("%0*d", len(dotParts[0]), version.Major),
|
||||||
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
|
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
|
||||||
fmt.Sprintf(
|
fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch),
|
||||||
"%0*d.%0*d.%0*d",
|
|
||||||
len(dotParts[0]),
|
|
||||||
version.Major,
|
|
||||||
len(dotParts[1]),
|
|
||||||
version.Minor,
|
|
||||||
len(dotParts[2]),
|
|
||||||
version.Patch,
|
|
||||||
),
|
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UseDefaultTag to keep only default branch for latest tag.
|
// UseDefaultTag for keep only default branch for latest tag
|
||||||
func UseDefaultTag(ref, defaultBranch string) bool {
|
func UseDefaultTag(ref, defaultBranch string) bool {
|
||||||
if strings.HasPrefix(ref, "refs/tags/") {
|
if strings.HasPrefix(ref, "refs/tags/") {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if stripHeadPrefix(ref) == defaultBranch {
|
if stripHeadPrefix(ref) == defaultBranch {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +89,5 @@ func stripHeadPrefix(ref string) string {
|
||||||
func stripTagPrefix(ref string) string {
|
func stripTagPrefix(ref string) string {
|
||||||
ref = strings.TrimPrefix(ref, "refs/tags/")
|
ref = strings.TrimPrefix(ref, "refs/tags/")
|
||||||
ref = strings.TrimPrefix(ref, "v")
|
ref = strings.TrimPrefix(ref, "v")
|
||||||
|
|
||||||
return ref
|
return ref
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_stripTagPrefix(t *testing.T) {
|
func Test_stripTagPrefix(t *testing.T) {
|
||||||
tests := []struct {
|
var tests = []struct {
|
||||||
Before string
|
Before string
|
||||||
After string
|
After string
|
||||||
}{
|
}{
|
||||||
|
@ -24,12 +24,12 @@ func Test_stripTagPrefix(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultTags(t *testing.T) {
|
func TestDefaultTags(t *testing.T) {
|
||||||
tests := []struct {
|
var tests = []struct {
|
||||||
Before string
|
Before string
|
||||||
After []string
|
After []string
|
||||||
}{
|
}{
|
||||||
{"", []string{"latest"}},
|
{"", []string{"latest"}},
|
||||||
{"refs/heads/main", []string{"latest"}},
|
{"refs/heads/master", []string{"latest"}},
|
||||||
{"refs/tags/0.9.0", []string{"0.9", "0.9.0"}},
|
{"refs/tags/0.9.0", []string{"0.9", "0.9.0"}},
|
||||||
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
|
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
|
||||||
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
|
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
|
||||||
|
@ -40,10 +40,8 @@ func TestDefaultTags(t *testing.T) {
|
||||||
tags, err := DefaultTags(test.Before)
|
tags, err := DefaultTags(test.Before)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
got, want := tags, test.After
|
got, want := tags, test.After
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("Got tag %v, want %v", got, want)
|
t.Errorf("Got tag %v, want %v", got, want)
|
||||||
|
@ -52,7 +50,7 @@ func TestDefaultTags(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultTagsError(t *testing.T) {
|
func TestDefaultTagsError(t *testing.T) {
|
||||||
tests := []string{
|
var tests = []string{
|
||||||
"refs/tags/x1.0.0",
|
"refs/tags/x1.0.0",
|
||||||
"refs/tags/20190203",
|
"refs/tags/20190203",
|
||||||
}
|
}
|
||||||
|
@ -66,7 +64,7 @@ func TestDefaultTagsError(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultTagSuffix(t *testing.T) {
|
func TestDefaultTagSuffix(t *testing.T) {
|
||||||
tests := []struct {
|
var tests = []struct {
|
||||||
Before string
|
Before string
|
||||||
Suffix string
|
Suffix string
|
||||||
After []string
|
After []string
|
||||||
|
@ -125,10 +123,8 @@ func TestDefaultTagSuffix(t *testing.T) {
|
||||||
tag, err := DefaultTagSuffix(test.Before, test.Suffix)
|
tag, err := DefaultTagSuffix(test.Before, test.Suffix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
got, want := tag, test.After
|
got, want := tag, test.After
|
||||||
if !reflect.DeepEqual(got, want) {
|
if !reflect.DeepEqual(got, want) {
|
||||||
t.Errorf("Got tag %v, want %v", got, want)
|
t.Errorf("Got tag %v, want %v", got, want)
|
||||||
|
@ -140,19 +136,17 @@ func Test_stripHeadPrefix(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
ref string
|
ref string
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
args args
|
args args
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/master",
|
||||||
},
|
},
|
||||||
want: "main",
|
want: "master",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := stripHeadPrefix(tt.args.ref); got != tt.want {
|
if got := stripHeadPrefix(tt.args.ref); got != tt.want {
|
||||||
t.Errorf("stripHeadPrefix() = %v, want %v", got, tt.want)
|
t.Errorf("stripHeadPrefix() = %v, want %v", got, tt.want)
|
||||||
|
@ -165,7 +159,6 @@ func TestUseDefaultTag(t *testing.T) {
|
||||||
ref string
|
ref string
|
||||||
defaultBranch string
|
defaultBranch string
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
|
@ -174,8 +167,8 @@ func TestUseDefaultTag(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "latest tag for default branch",
|
name: "latest tag for default branch",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/main",
|
ref: "refs/heads/master",
|
||||||
defaultBranch: "main",
|
defaultBranch: "master",
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
@ -183,7 +176,7 @@ func TestUseDefaultTag(t *testing.T) {
|
||||||
name: "build from tags",
|
name: "build from tags",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/tags/v1.0.0",
|
ref: "refs/tags/v1.0.0",
|
||||||
defaultBranch: "main",
|
defaultBranch: "master",
|
||||||
},
|
},
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
|
@ -191,12 +184,11 @@ func TestUseDefaultTag(t *testing.T) {
|
||||||
name: "skip build for not default branch",
|
name: "skip build for not default branch",
|
||||||
args: args{
|
args: args{
|
||||||
ref: "refs/heads/develop",
|
ref: "refs/heads/develop",
|
||||||
defaultBranch: "main",
|
defaultBranch: "master",
|
||||||
},
|
},
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := UseDefaultTag(tt.args.ref, tt.args.defaultBranch); got != tt.want {
|
if got := UseDefaultTag(tt.args.ref, tt.args.defaultBranch); got != tt.want {
|
||||||
t.Errorf("%q. UseDefaultTag() = %v, want %v", tt.name, got, tt.want)
|
t.Errorf("%q. UseDefaultTag() = %v, want %v", tt.name, got, tt.want)
|
||||||
|
|
4
renovate.json
Normal file
4
renovate.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
|
"extends": ["github>thegeeklab/renovate-presets"]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user