diff --git a/.drone.jsonnet b/.drone.jsonnet index e92a41c..99832f4 100644 --- a/.drone.jsonnet +++ b/.drone.jsonnet @@ -21,6 +21,15 @@ local pipeline = import 'pipeline.libsonnet'; 'linux-arm', ]), + pipeline.build('acr', 'linux', 'amd64'), + pipeline.build('acr', 'linux', 'arm64'), + pipeline.build('acr', 'linux', 'arm'), + pipeline.notifications('acr', depends_on=[ + 'linux-amd64', + 'linux-arm64', + 'linux-arm', + ]), + pipeline.build('ecr', 'linux', 'amd64'), pipeline.build('ecr', 'linux', 'arm64'), pipeline.build('ecr', 'linux', 'arm'), diff --git a/.drone.windows.jsonnet b/.drone.windows.jsonnet index bd0a92d..23475af 100644 --- a/.drone.windows.jsonnet +++ b/.drone.windows.jsonnet @@ -17,6 +17,13 @@ local pipeline = import 'pipeline.libsonnet'; 'windows-1809' ]), + pipeline.build('acr', 'windows', 'amd64', '1803'), + pipeline.build('acr', 'windows', 'amd64', '1809'), + pipeline.notifications('acr', 'windows', 'amd64', '1809', [ + 'windows-1803', + 'windows-1809' + ]), + pipeline.build('ecr', 'windows', 'amd64', '1803'), pipeline.build('ecr', 'windows', 'amd64', '1809'), pipeline.notifications('ecr', 'windows', 'amd64', '1809', [ diff --git a/.drone.windows.yml b/.drone.windows.yml index aaccb3d..ab11bfe 100644 --- a/.drone.windows.yml +++ b/.drone.windows.yml @@ -706,4 +706,221 @@ depends_on: - windows-1803-ecr - windows-1809-ecr +--- +kind: pipeline +name: windows-1803-acr + +platform: + os: windows + arch: amd64 + version: 1803 + +steps: +- name: build-push + pull: always + image: golang:1.11-windowsservercore-1803 + commands: + - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + exclude: + - tag + +- name: build-tag + pull: always + image: golang:1.11-windowsservercore-1803 + commands: + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + - tag + +- name: dryrun + pull: always + image: plugins/docker:windows-1803 + settings: + daemon_off: true + dockerfile: docker/acr/Dockerfile.windows.1803 + dry_run: true + password: + from_secret: docker_password + repo: plugins/acr + tags: windows-1803 + username: + from_secret: docker_username + volumes: + - name: docker_pipe + path: \\\\.\\pipe\\docker_engine + when: + event: + - pull_request + +- name: publish + pull: always + image: plugins/docker:windows-1803 + settings: + auto_tag: true + auto_tag_suffix: windows-1803 + daemon_off: true + dockerfile: docker/acr/Dockerfile.windows.1803 + password: + from_secret: docker_password + repo: plugins/acr + username: + from_secret: docker_username + volumes: + - name: docker_pipe + path: \\\\.\\pipe\\docker_engine + when: + event: + exclude: + - pull_request + +volumes: +- name: docker_pipe + host: + path: \\\\.\\pipe\\docker_engine + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- windows-1803-docker + +--- +kind: pipeline +name: windows-1809-acr + +platform: + os: windows + arch: amd64 + version: 1809 + +steps: +- name: build-push + pull: always + image: golang:1.11-windowsservercore-1809 + commands: + - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + exclude: + - tag + +- name: build-tag + pull: always + image: golang:1.11-windowsservercore-1809 + commands: + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + - tag + +- name: dryrun + pull: always + image: plugins/docker:windows-1809 + settings: + daemon_off: true + dockerfile: docker/acr/Dockerfile.windows.1809 + dry_run: true + password: + from_secret: docker_password + repo: plugins/acr + tags: windows-1809 + username: + from_secret: docker_username + volumes: + - name: docker_pipe + path: \\\\.\\pipe\\docker_engine + when: + event: + - pull_request + +- name: publish + pull: always + image: plugins/docker:windows-1809 + settings: + auto_tag: true + auto_tag_suffix: windows-1809 + daemon_off: true + dockerfile: docker/acr/Dockerfile.windows.1809 + password: + from_secret: docker_password + repo: plugins/acr + username: + from_secret: docker_username + volumes: + - name: docker_pipe + path: \\\\.\\pipe\\docker_engine + when: + event: + exclude: + - pull_request + +volumes: +- name: docker_pipe + host: + path: \\\\.\\pipe\\docker_engine + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- windows-1809-docker + +--- +kind: pipeline +name: notifications-acr + +platform: + os: windows + arch: amd64 + version: 1809 + +steps: +- name: manifest + pull: always + image: plugins/manifest + settings: + ignore_missing: true + password: + from_secret: docker_password + spec: docker/acr/manifest.tmpl + username: + from_secret: docker_username + +- name: microbadger + pull: always + image: plugins/webhook + settings: + url: + from_secret: microbadger_acr + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + +depends_on: +- windows-1803-acr +- windows-1809-acr + ... diff --git a/.drone.yml b/.drone.yml index a2c0a96..fdb4069 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1145,4 +1145,276 @@ depends_on: - linux-arm64-heroku - linux-arm-heroku +--- +kind: pipeline +name: linux-amd64-acr + +platform: + os: linux + arch: amd64 + +steps: +- name: build-push + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + exclude: + - tag + +- name: build-tag + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + - tag + +- name: dryrun + pull: always + image: plugins/docker:linux-amd64 + settings: + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.amd64 + dry_run: true + password: + from_secret: docker_password + repo: plugins/acr + tags: linux-amd64 + username: + from_secret: docker_username + when: + event: + - pull_request + +- name: publish + pull: always + image: plugins/docker:linux-amd64 + settings: + auto_tag: true + auto_tag_suffix: linux-amd64 + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.amd64 + password: + from_secret: docker_password + repo: plugins/acr + username: + from_secret: docker_username + when: + event: + exclude: + - pull_request + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- linux-amd64-docker + +--- +kind: pipeline +name: linux-arm64-acr + +platform: + os: linux + arch: arm64 + +steps: +- name: build-push + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + exclude: + - tag + +- name: build-tag + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm64/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + - tag + +- name: dryrun + pull: always + image: plugins/docker:linux-arm64 + settings: + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.arm64 + dry_run: true + password: + from_secret: docker_password + repo: plugins/acr + tags: linux-arm64 + username: + from_secret: docker_username + when: + event: + - pull_request + +- name: publish + pull: always + image: plugins/docker:linux-arm64 + settings: + auto_tag: true + auto_tag_suffix: linux-arm64 + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.arm64 + password: + from_secret: docker_password + repo: plugins/acr + username: + from_secret: docker_username + when: + event: + exclude: + - pull_request + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- linux-arm64-docker + +--- +kind: pipeline +name: linux-arm-acr + +platform: + os: linux + arch: arm + +steps: +- name: build-push + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + exclude: + - tag + +- name: build-tag + pull: always + image: golang:1.11 + commands: + - "go build -v -ldflags \"-X main.version=${DRONE_TAG##v} -X main.build=${DRONE_BUILD_NUMBER}\" -a -tags netgo -o release/linux/arm/drone-acr ./cmd/drone-acr" + environment: + CGO_ENABLED: 0 + GO111MODULE: on + when: + event: + - tag + +- name: dryrun + pull: always + image: plugins/docker:linux-arm + settings: + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.arm + dry_run: true + password: + from_secret: docker_password + repo: plugins/acr + tags: linux-arm + username: + from_secret: docker_username + when: + event: + - pull_request + +- name: publish + pull: always + image: plugins/docker:linux-arm + settings: + auto_tag: true + auto_tag_suffix: linux-arm + daemon_off: false + dockerfile: docker/acr/Dockerfile.linux.arm + password: + from_secret: docker_password + repo: plugins/acr + username: + from_secret: docker_username + when: + event: + exclude: + - pull_request + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + - "refs/pull/**" + +depends_on: +- linux-arm-docker + +--- +kind: pipeline +name: notifications-acr + +platform: + os: linux + arch: amd64 + +steps: +- name: manifest + pull: always + image: plugins/manifest + settings: + ignore_missing: true + password: + from_secret: docker_password + spec: docker/acr/manifest.tmpl + username: + from_secret: docker_username + +- name: microbadger + pull: always + image: plugins/webhook + settings: + url: + from_secret: microbadger_acr + +trigger: + ref: + - refs/heads/master + - "refs/tags/**" + +depends_on: +- linux-amd64-acr +- linux-arm64-acr +- linux-arm-acr + + ... diff --git a/README.md b/README.md index fc6ebd6..9f42efc 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ export GO111MODULE=on go build -v -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker go build -v -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr go build -v -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr +go build -v -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr go build -v -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku ``` @@ -46,6 +47,11 @@ docker build \ --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ --file docker/ecr/Dockerfile.linux.amd64 --tag plugins/ecr . +docker build \ + --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ + --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ + --file docker/acr/Dockerfile.linux.amd64 --tag plugins/acr . + docker build \ --label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ --label org.label-schema.vcs-ref=$(git rev-parse --short HEAD) \ diff --git a/cmd/drone-acr/main.go b/cmd/drone-acr/main.go new file mode 100644 index 0000000..6ef7696 --- /dev/null +++ b/cmd/drone-acr/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "strings" +) + +func main() { + var ( + repo = getenv("PLUGIN_REPO") + registry = getenv("PLUGIN_REGISTRY") + username = getenv("SERVICE_PRINCIPAL_CLIENT_ID") + password = getenv("SERVICE_PRINCIPAL_CLIENT_SECRET") + ) + + // default registry value + if registry == "" { + registry = "azurecr.io" + } + + // must use the fully qualified repo name. If the + // repo name does not have the registry prefix we + // should prepend. + if !strings.HasPrefix(repo, registry) { + repo = fmt.Sprintf("%s/%s", registry, repo) + } + + os.Setenv("PLUGIN_REPO", repo) + os.Setenv("PLUGIN_REGISTRY", registry) + os.Setenv("DOCKER_USERNAME", username) + os.Setenv("DOCKER_PASSWORD", password) + + // invoke the base docker plugin binary + cmd := exec.Command("drone-docker") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + err := cmd.Run() + if err != nil { + os.Exit(1) + } +} + +func getenv(key ...string) (s string) { + for _, k := range key { + s = os.Getenv(k) + if s != "" { + return + } + } + return +} diff --git a/docker/acr/Dockerfile.linux.amd64 b/docker/acr/Dockerfile.linux.amd64 new file mode 100644 index 0000000..7de72ed --- /dev/null +++ b/docker/acr/Dockerfile.linux.amd64 @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-amd64 + +ADD release/linux/amd64/drone-acr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-acr"] diff --git a/docker/acr/Dockerfile.linux.arm b/docker/acr/Dockerfile.linux.arm new file mode 100644 index 0000000..c989857 --- /dev/null +++ b/docker/acr/Dockerfile.linux.arm @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm + +ADD release/linux/arm/drone-acr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-acr"] diff --git a/docker/acr/Dockerfile.linux.arm64 b/docker/acr/Dockerfile.linux.arm64 new file mode 100644 index 0000000..772022d --- /dev/null +++ b/docker/acr/Dockerfile.linux.arm64 @@ -0,0 +1,4 @@ +FROM plugins/docker:linux-arm64 + +ADD release/linux/arm64/drone-acr /bin/ +ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-acr"] diff --git a/docker/acr/Dockerfile.windows.1803 b/docker/acr/Dockerfile.windows.1803 new file mode 100644 index 0000000..f7b3fdd --- /dev/null +++ b/docker/acr/Dockerfile.windows.1803 @@ -0,0 +1,10 @@ +# escape=` +FROM plugins/docker:windows-1803 + +LABEL maintainer="Drone.IO Community " ` + org.label-schema.name="Drone ACR" ` + org.label-schema.vendor="Drone.IO Community" ` + org.label-schema.schema-version="1.0" + +ADD release/windows/amd64/drone-acr.exe C:/bin/drone-acr.exe +ENTRYPOINT [ "C:\\bin\\drone-acr.exe" ] diff --git a/docker/acr/Dockerfile.windows.1809 b/docker/acr/Dockerfile.windows.1809 new file mode 100644 index 0000000..dfa264d --- /dev/null +++ b/docker/acr/Dockerfile.windows.1809 @@ -0,0 +1,10 @@ +# escape=` +FROM plugins/docker:windows-1809 + +LABEL maintainer="Drone.IO Community " ` + org.label-schema.name="Drone ACR" ` + org.label-schema.vendor="Drone.IO Community" ` + org.label-schema.schema-version="1.0" + +ADD release/windows/amd64/drone-acr.exe C:/bin/drone-acr.exe +ENTRYPOINT [ "C:\\bin\\drone-acr.exe" ] diff --git a/docker/acr/manifest.tmpl b/docker/acr/manifest.tmpl new file mode 100644 index 0000000..d1acb34 --- /dev/null +++ b/docker/acr/manifest.tmpl @@ -0,0 +1,37 @@ +image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} +{{#if build.tags}} +tags: +{{#each build.tags}} + - {{this}} +{{/each}} +{{/if}} +manifests: + - + image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 + platform: + architecture: amd64 + os: linux + - + image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 + platform: + architecture: arm64 + os: linux + variant: v8 + - + image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm + platform: + architecture: arm + os: linux + variant: v7 + - + image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803 + platform: + architecture: amd64 + os: windows + version: 1803 + - + image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 + platform: + architecture: amd64 + os: windows + version: 1809