mirror of
https://github.com/drone-plugins/drone-docker.git
synced 2026-06-04 18:24:24 +08:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 44157a2e29 | |||
| feb90fe92d | |||
| 55c76aeaf0 | |||
| b54379f077 | |||
| ab3fed4710 | |||
| e62984fe46 | |||
| c48ca605a4 | |||
| 0e03ef3eab | |||
| 7a498e78b2 | |||
| 2140a2be40 | |||
| dcc762d301 | |||
| b318c15acb | |||
| 86de147dc8 | |||
| 68605049b7 | |||
| e2e30f3015 | |||
| 4999d4ca01 | |||
| b28dae76d7 | |||
| 9530538f5c | |||
| 27660b1342 | |||
| 81ce3b6d2e | |||
| 3c461ba65b | |||
| e1e1a6c7dc | |||
| f202de1604 | |||
| 60929c782c | |||
| 90280c9c7b | |||
| 531cc5cb7a | |||
| a5459e5f20 | |||
| 6ae21e3d8c | |||
| bee421255a | |||
| a6b3e2f7b5 | |||
| 6cade1e98b | |||
| 0a2f635d57 | |||
| 74d5558af0 | |||
| 5639b702aa | |||
| 9a4e1ba483 | |||
| ced9875ed0 | |||
| e9b38c94b4 | |||
| 292ebe06de | |||
| 49e9dde7a7 | |||
| e7e8dd882d | |||
| 11015f0ddb | |||
| a946428e81 | |||
| 7c8c6ca9cb | |||
| 87212938c2 | |||
| 3c4c8e5f10 | |||
| b009c711b5 | |||
| 12cc40aa62 | |||
| a807dc91eb | |||
| e0ceb37f24 | |||
| 939591f018 | |||
| 755ae001f9 | |||
| 757a756d1a |
+213
-33
@@ -12,7 +12,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: vet
|
||||
image: golang:1.21
|
||||
image: golang:1.22.4
|
||||
commands:
|
||||
- go vet ./...
|
||||
environment:
|
||||
@@ -22,7 +22,7 @@ steps:
|
||||
path: /go
|
||||
|
||||
- name: test
|
||||
image: golang:1.21
|
||||
image: golang:1.22.4
|
||||
commands:
|
||||
- go test -cover ./...
|
||||
environment:
|
||||
@@ -55,7 +55,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: go build
|
||||
image: golang:1.21
|
||||
image: golang:1.22.4
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
@@ -63,6 +63,8 @@ steps:
|
||||
- go build -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr
|
||||
- go build -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr
|
||||
- go build -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr
|
||||
- go build -o release/windows/amd64/drone-gar.exe ./cmd/drone-gar
|
||||
|
||||
- name: build docker plugin
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
@@ -123,7 +125,21 @@ steps:
|
||||
purge: false
|
||||
when:
|
||||
event: [push, tag]
|
||||
|
||||
- name: build gar plugin
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
pull: never
|
||||
settings:
|
||||
dockerfile: docker/gar/Dockerfile.windows.amd64.1809
|
||||
repo: plugins/gar
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: windows-1809-amd64
|
||||
purge: false
|
||||
when:
|
||||
event: [push, tag]
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
@@ -146,7 +162,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: go build
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
commands:
|
||||
@@ -154,8 +170,9 @@ steps:
|
||||
- go build -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr
|
||||
- go build -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr
|
||||
- go build -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr
|
||||
- go build -o release/windows/amd64/drone-gar.exe ./cmd/drone-gar
|
||||
- name: build docker plugin
|
||||
image: plugins/docker
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
dockerfile: docker/docker/Dockerfile.windows.amd64.ltsc2022
|
||||
repo: plugins/docker
|
||||
@@ -169,7 +186,7 @@ steps:
|
||||
when:
|
||||
event: [push, tag]
|
||||
- name: build ecr plugin
|
||||
image: plugins/docker
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
dockerfile: docker/ecr/Dockerfile.windows.amd64.ltsc2022
|
||||
repo: plugins/ecr
|
||||
@@ -183,7 +200,7 @@ steps:
|
||||
when:
|
||||
event: [push, tag]
|
||||
- name: build gcr plugin
|
||||
image: plugins/docker
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
dockerfile: docker/gcr/Dockerfile.windows.amd64.ltsc2022
|
||||
repo: plugins/gcr
|
||||
@@ -197,7 +214,7 @@ steps:
|
||||
when:
|
||||
event: [push, tag]
|
||||
- name: build acr plugin
|
||||
image: plugins/docker
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
dockerfile: docker/acr/Dockerfile.windows.amd64.ltsc2022
|
||||
repo: plugins/acr
|
||||
@@ -210,7 +227,20 @@ steps:
|
||||
purge: false
|
||||
when:
|
||||
event: [push, tag]
|
||||
|
||||
- name: build gar plugin
|
||||
image: plugins/docker@sha256:f0233d950ae87ee6cb5500b2d5497fe02aa338201c0bdce2619f443fd174cfa4
|
||||
settings:
|
||||
dockerfile: docker/gar/Dockerfile.windows.amd64.ltsc2022
|
||||
repo: plugins/gar
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
auto_tag: true
|
||||
auto_tag_suffix: windows-ltsc2022-amd64
|
||||
purge: false
|
||||
when:
|
||||
event: [push, tag]
|
||||
depends_on:
|
||||
- testing
|
||||
|
||||
@@ -234,7 +264,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker'
|
||||
environment:
|
||||
@@ -245,7 +275,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-docker ./cmd/drone-docker'
|
||||
environment:
|
||||
@@ -255,7 +285,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: executable
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- ./release/linux/amd64/drone-docker --help
|
||||
|
||||
@@ -299,7 +329,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker'
|
||||
environment:
|
||||
@@ -310,7 +340,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-docker ./cmd/drone-docker'
|
||||
environment:
|
||||
@@ -320,7 +350,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: executable
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- ./release/linux/arm64/drone-docker --help
|
||||
|
||||
@@ -399,7 +429,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr'
|
||||
environment:
|
||||
@@ -410,7 +440,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-gcr ./cmd/drone-gcr'
|
||||
environment:
|
||||
@@ -444,7 +474,6 @@ trigger:
|
||||
|
||||
depends_on:
|
||||
- linux-amd64-docker
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-arm64-gcr
|
||||
@@ -459,7 +488,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr'
|
||||
environment:
|
||||
@@ -470,7 +499,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-gcr ./cmd/drone-gcr'
|
||||
environment:
|
||||
@@ -539,7 +568,158 @@ depends_on:
|
||||
- windows-ltsc2022
|
||||
- linux-amd64-gcr
|
||||
- linux-arm64-gcr
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-amd64-gar
|
||||
type: vm
|
||||
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-gar ./cmd/drone-gar'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-gar ./cmd/drone-gar'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
- name: publish
|
||||
image: plugins/docker:18
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-amd64
|
||||
daemon_off: false
|
||||
dockerfile: docker/gar/Dockerfile.linux.amd64
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: plugins/gar
|
||||
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-gar
|
||||
type: vm
|
||||
|
||||
pool:
|
||||
use: ubuntu_arm64
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: arm64
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-gar ./cmd/drone-gar'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-gar ./cmd/drone-gar'
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
|
||||
- name: publish
|
||||
image: plugins/docker:18
|
||||
settings:
|
||||
auto_tag: true
|
||||
auto_tag_suffix: linux-arm64
|
||||
daemon_off: false
|
||||
dockerfile: docker/gar/Dockerfile.linux.arm64
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: plugins/gar
|
||||
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: notifications-gar
|
||||
type: vm
|
||||
|
||||
pool:
|
||||
use: ubuntu
|
||||
|
||||
platform:
|
||||
os: linux
|
||||
arch: amd64
|
||||
|
||||
steps:
|
||||
- name: manifest
|
||||
image: plugins/manifest
|
||||
settings:
|
||||
auto_tag: true
|
||||
ignore_missing: true
|
||||
password:
|
||||
from_secret: docker_password
|
||||
spec: docker/gar/manifest.tmpl
|
||||
username:
|
||||
from_secret: docker_username
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- "refs/tags/**"
|
||||
|
||||
depends_on:
|
||||
- windows-1809
|
||||
- windows-ltsc2022
|
||||
- linux-amd64-gar
|
||||
- linux-arm64-gar
|
||||
---
|
||||
kind: pipeline
|
||||
name: linux-amd64-ecr
|
||||
@@ -554,7 +734,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr'
|
||||
environment:
|
||||
@@ -564,7 +744,7 @@ steps:
|
||||
exclude:
|
||||
- tag
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-ecr ./cmd/drone-ecr'
|
||||
environment:
|
||||
@@ -612,7 +792,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr'
|
||||
environment:
|
||||
@@ -622,7 +802,7 @@ steps:
|
||||
exclude:
|
||||
- tag
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-ecr ./cmd/drone-ecr'
|
||||
environment:
|
||||
@@ -705,7 +885,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku'
|
||||
environment:
|
||||
@@ -715,7 +895,7 @@ steps:
|
||||
exclude:
|
||||
- tag
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/amd64/drone-heroku ./cmd/drone-heroku'
|
||||
environment:
|
||||
@@ -764,7 +944,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_COMMIT_SHA:0:8}" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku'
|
||||
environment:
|
||||
@@ -774,7 +954,7 @@ steps:
|
||||
exclude:
|
||||
- tag
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.version=${DRONE_TAG##v}" -a -tags netgo -o release/linux/arm64/drone-heroku ./cmd/drone-heroku'
|
||||
environment:
|
||||
@@ -855,7 +1035,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/amd64/drone-acr ./cmd/drone-acr'
|
||||
environment:
|
||||
@@ -865,7 +1045,7 @@ steps:
|
||||
exclude:
|
||||
- tag
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
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:
|
||||
@@ -913,7 +1093,7 @@ platform:
|
||||
|
||||
steps:
|
||||
- name: build-push
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
commands:
|
||||
- 'go build -v -ldflags "-X main.build=${DRONE_BUILD_NUMBER}" -a -tags netgo -o release/linux/arm64/drone-acr ./cmd/drone-acr'
|
||||
environment:
|
||||
@@ -924,7 +1104,7 @@ steps:
|
||||
- tag
|
||||
|
||||
- name: build-tag
|
||||
image: golang:1.21
|
||||
image: golang:1.22.7
|
||||
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:
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
inputSet:
|
||||
name: event-PR
|
||||
tags: {}
|
||||
identifier: eventPR
|
||||
orgIdentifier: default
|
||||
projectIdentifier: Drone_Plugins
|
||||
pipeline:
|
||||
identifier: dronedockerharness
|
||||
properties:
|
||||
ci:
|
||||
codebase:
|
||||
build:
|
||||
type: PR
|
||||
spec:
|
||||
number: <+trigger.prNumber>
|
||||
stages:
|
||||
- parallel:
|
||||
- stage:
|
||||
identifier: linamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Build_Push
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/amd64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
auto_tag_suffix: linux-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
- stage:
|
||||
identifier: linarm64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: buildpush
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/arm64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
auto_tag_suffix: linux-arm64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-arm64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
- stage:
|
||||
identifier: win1809amd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
auto_tag_suffix: windows-1809-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-1809-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
- stage:
|
||||
identifier: winamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
auto_tag_suffix: windows-ltsc2022-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-ltsc2022-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
- stage:
|
||||
identifier: Manifest
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Plugin_1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
spec: docker/<+matrix.repo>/manifest.tmpl
|
||||
@@ -0,0 +1,127 @@
|
||||
inputSet:
|
||||
name: event-Push
|
||||
tags: {}
|
||||
identifier: eventPush
|
||||
orgIdentifier: default
|
||||
projectIdentifier: Drone_Plugins
|
||||
pipeline:
|
||||
identifier: dronedockerharness
|
||||
properties:
|
||||
ci:
|
||||
codebase:
|
||||
build:
|
||||
type: branch
|
||||
spec:
|
||||
branch: <+trigger.branch>
|
||||
stages:
|
||||
- parallel:
|
||||
- stage:
|
||||
identifier: linamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Build_Push
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/amd64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
auto_tag_suffix: linux-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
- stage:
|
||||
identifier: linarm64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: buildpush
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/arm64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
auto_tag_suffix: linux-arm64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-arm64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
- stage:
|
||||
identifier: win1809amd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
auto_tag_suffix: windows-1809-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-1809-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
- stage:
|
||||
identifier: winamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
auto_tag_suffix: windows-ltsc2022-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-ltsc2022-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
- stage:
|
||||
identifier: Manifest
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Plugin_1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
spec: docker/<+matrix.repo>/manifest.tmpl
|
||||
@@ -0,0 +1,127 @@
|
||||
inputSet:
|
||||
name: event-Tag
|
||||
tags: {}
|
||||
identifier: eventTag
|
||||
orgIdentifier: default
|
||||
projectIdentifier: Drone_Plugins
|
||||
pipeline:
|
||||
identifier: dronedockerharness
|
||||
properties:
|
||||
ci:
|
||||
codebase:
|
||||
build:
|
||||
type: tag
|
||||
spec:
|
||||
tag: <+trigger.tag>
|
||||
stages:
|
||||
- parallel:
|
||||
- stage:
|
||||
identifier: linamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Build_Push
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/amd64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
auto_tag_suffix: linux-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.amd64
|
||||
- stage:
|
||||
identifier: linarm64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: buildpush
|
||||
type: Run
|
||||
spec:
|
||||
command: go build -a -tags netgo -o release/linux/arm64/drone-<+matrix.repo> ./cmd/drone-<+matrix.repo>
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
auto_tag_suffix: linux-arm64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- linux-arm64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.linux.arm64
|
||||
- stage:
|
||||
identifier: win1809amd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
auto_tag_suffix: windows-1809-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-1809-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.1809
|
||||
- stage:
|
||||
identifier: winamd64
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Docker_Build_and_Push1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
repo: plugins/<+matrix.repo>
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
auto_tag_suffix: windows-ltsc2022-amd64
|
||||
- step:
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
type: BuildAndPushDockerRegistry
|
||||
spec:
|
||||
repo: plugins/<+matrix.repo>
|
||||
tags:
|
||||
- windows-ltsc2022-amd64
|
||||
dockerfile: docker/<+matrix.repo>/Dockerfile.windows.amd64.ltsc2022
|
||||
- stage:
|
||||
identifier: Manifest
|
||||
type: CI
|
||||
spec:
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
identifier: Plugin_1
|
||||
type: Plugin
|
||||
spec:
|
||||
settings:
|
||||
spec: docker/<+matrix.repo>/manifest.tmpl
|
||||
@@ -0,0 +1,382 @@
|
||||
pipeline:
|
||||
orgIdentifier: default
|
||||
tags: {}
|
||||
properties:
|
||||
ci:
|
||||
codebase:
|
||||
connectorRef: GitHub_Drone_Plugins_Org
|
||||
repoName: drone-docker
|
||||
build: <+input>
|
||||
sparseCheckout: []
|
||||
stages:
|
||||
- stage:
|
||||
name: Test
|
||||
identifier: Test
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: false
|
||||
paths: []
|
||||
platform:
|
||||
os: Linux
|
||||
arch: Amd64
|
||||
runtime:
|
||||
type: Cloud
|
||||
spec: {}
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Run
|
||||
name: GO VET
|
||||
identifier: Run_1
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: go vet ./...
|
||||
- step:
|
||||
type: Run
|
||||
name: GO TEST
|
||||
identifier: Run_2
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: go test -cover ./...
|
||||
- parallel:
|
||||
- stage:
|
||||
name: linux-amd64
|
||||
identifier: linamd64
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: false
|
||||
paths: []
|
||||
platform:
|
||||
os: Linux
|
||||
arch: Amd64
|
||||
runtime:
|
||||
type: Cloud
|
||||
spec: {}
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Run
|
||||
name: Build Binary
|
||||
identifier: Build_Push
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: <+input>
|
||||
envVariables:
|
||||
CGO_ENABLED: "0"
|
||||
- step:
|
||||
type: Plugin
|
||||
name: Build and Push on Tag
|
||||
identifier: Docker_Build_and_Push
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username: drone
|
||||
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
|
||||
repo: <+input>
|
||||
dockerfile: <+input>
|
||||
auto_tag: "true"
|
||||
auto_tag_suffix: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "tag"
|
||||
- step:
|
||||
type: BuildAndPushDockerRegistry
|
||||
name: Build and Push on Branch
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
repo: <+input>
|
||||
tags: <+input>
|
||||
caching: true
|
||||
dockerfile: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "branch"
|
||||
strategy:
|
||||
matrix:
|
||||
repo:
|
||||
- docker
|
||||
- gcr
|
||||
- gar
|
||||
- ecr
|
||||
- heroku
|
||||
- acr
|
||||
- stage:
|
||||
name: linux-arm64
|
||||
identifier: linarm64
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: false
|
||||
paths: []
|
||||
platform:
|
||||
os: Linux
|
||||
arch: Arm64
|
||||
runtime:
|
||||
type: Cloud
|
||||
spec: {}
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Run
|
||||
name: Build Binary
|
||||
identifier: buildpush
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: <+input>
|
||||
envVariables:
|
||||
CGO_ENABLED: "0"
|
||||
- step:
|
||||
type: Plugin
|
||||
name: Build and Push on Tag
|
||||
identifier: Docker_Build_and_Push
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username: drone
|
||||
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
|
||||
repo: <+input>
|
||||
dockerfile: <+input>
|
||||
auto_tag: "true"
|
||||
auto_tag_suffix: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "tag"
|
||||
- step:
|
||||
type: BuildAndPushDockerRegistry
|
||||
name: Build and Push on Branch
|
||||
identifier: BuildAndPushDockerRegistry_1
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
repo: <+input>
|
||||
tags: <+input>
|
||||
caching: true
|
||||
dockerfile: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "branch"
|
||||
strategy:
|
||||
matrix:
|
||||
repo:
|
||||
- docker
|
||||
- gcr
|
||||
- gar
|
||||
- ecr
|
||||
- heroku
|
||||
- acr
|
||||
- stage:
|
||||
name: win-1809-amd64
|
||||
identifier: win1809amd64
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: true
|
||||
infrastructure:
|
||||
type: VM
|
||||
spec:
|
||||
type: Pool
|
||||
spec:
|
||||
poolName: windows-2019
|
||||
os: Windows
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Run
|
||||
name: Build Binary
|
||||
identifier: go_build
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: |-
|
||||
# disable cgo
|
||||
export CGO_ENABLED=0
|
||||
|
||||
go build -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker
|
||||
go build -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr
|
||||
go build -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr
|
||||
go build -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr
|
||||
go build -o release/windows/amd64/drone-gar.exe ./cmd/drone-gar
|
||||
- step:
|
||||
type: Plugin
|
||||
name: Build and Push on Tag
|
||||
identifier: Docker_Build_and_Push1
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username: drone
|
||||
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
|
||||
repo: <+input>
|
||||
dockerfile: <+input>
|
||||
auto_tag: "true"
|
||||
auto_tag_suffix: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "tag"
|
||||
- step:
|
||||
type: BuildAndPushDockerRegistry
|
||||
name: Build and Push on Branch
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
repo: <+input>
|
||||
tags: <+input>
|
||||
caching: true
|
||||
dockerfile: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "branch"
|
||||
strategy:
|
||||
matrix:
|
||||
repo:
|
||||
- docker
|
||||
- gcr
|
||||
- gar
|
||||
- ecr
|
||||
- acr
|
||||
delegateSelectors:
|
||||
- windows-vm
|
||||
- stage:
|
||||
name: win-ltsc2022-amd64
|
||||
identifier: winamd64
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: false
|
||||
paths: []
|
||||
platform:
|
||||
os: Windows
|
||||
arch: Amd64
|
||||
runtime:
|
||||
type: Cloud
|
||||
spec: {}
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Run
|
||||
name: Build Binary -ltsc2022
|
||||
identifier: build_amd64ltsc2022
|
||||
spec:
|
||||
connectorRef: account.harnessImage
|
||||
image: golang:1.22.4
|
||||
shell: Sh
|
||||
command: |-
|
||||
# disable cgo
|
||||
export CGO_ENABLED=0
|
||||
|
||||
go build -o release/windows/amd64/drone-docker.exe ./cmd/drone-docker
|
||||
go build -o release/windows/amd64/drone-ecr.exe ./cmd/drone-ecr
|
||||
go build -o release/windows/amd64/drone-gcr.exe ./cmd/drone-gcr
|
||||
go build -o release/windows/amd64/drone-acr.exe ./cmd/drone-acr
|
||||
go build -o release/windows/amd64/drone-gar.exe ./cmd/drone-gar
|
||||
envVariables:
|
||||
CGO_ENABLED: "0"
|
||||
- step:
|
||||
type: Plugin
|
||||
name: Build and Push on Tag
|
||||
identifier: Docker_Build_and_Push1
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username: drone
|
||||
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
|
||||
repo: <+input>
|
||||
dockerfile: <+input>
|
||||
auto_tag: "true"
|
||||
auto_tag_suffix: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "tag"
|
||||
- step:
|
||||
type: BuildAndPushDockerRegistry
|
||||
name: Build and Push on Branch
|
||||
identifier: BuildAndPushDockerRegistry_2
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
repo: <+input>
|
||||
tags: <+input>
|
||||
caching: true
|
||||
dockerfile: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "branch"
|
||||
buildIntelligence:
|
||||
enabled: false
|
||||
strategy:
|
||||
matrix:
|
||||
repo:
|
||||
- docker
|
||||
- gcr
|
||||
- gar
|
||||
- ecr
|
||||
- acr
|
||||
- stage:
|
||||
name: Manifest and Release
|
||||
identifier: Manifest
|
||||
description: ""
|
||||
type: CI
|
||||
spec:
|
||||
cloneCodebase: true
|
||||
caching:
|
||||
enabled: false
|
||||
paths: []
|
||||
execution:
|
||||
steps:
|
||||
- step:
|
||||
type: Plugin
|
||||
name: Manifest
|
||||
identifier: Plugin_1
|
||||
spec:
|
||||
connectorRef: Plugins_Docker_Hub_Connector
|
||||
image: plugins/manifest
|
||||
settings:
|
||||
username: drone
|
||||
password: <+secrets.getValue("Plugins_Docker_Hub_Pat")>
|
||||
auto_tag: "true"
|
||||
ignore_missing: "true"
|
||||
spec: <+input>
|
||||
when:
|
||||
stageStatus: Success
|
||||
condition: <+codebase.build.type> == "tag" || <+codebase.build.type> == "branch"
|
||||
platform:
|
||||
os: Linux
|
||||
arch: Amd64
|
||||
runtime:
|
||||
type: Cloud
|
||||
spec: {}
|
||||
strategy:
|
||||
matrix:
|
||||
repo:
|
||||
- docker
|
||||
- gcr
|
||||
- gar
|
||||
- ecr
|
||||
- heroku
|
||||
- acr
|
||||
identifier: dronedockerharness
|
||||
projectIdentifier: Drone_Plugins
|
||||
name: drone-docker-harness
|
||||
@@ -10,6 +10,14 @@
|
||||
|
||||
Drone plugin uses Docker-in-Docker to build and publish Docker images to a container registry. For the usage information and a listing of the available options please take a look at [the docs](http://plugins.drone.io/drone-plugins/drone-docker/).
|
||||
|
||||
### Git Leaks
|
||||
|
||||
Run the following script to install git-leaks support to this repo.
|
||||
```
|
||||
chmod +x ./git-hooks/install.sh
|
||||
./git-hooks/install.sh
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
Build the binaries with the following commands:
|
||||
@@ -25,6 +33,7 @@ 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
|
||||
go build -v -a -tags netgo -o release/linux/amd64/drone-gar ./cmd/drone-gar
|
||||
```
|
||||
|
||||
## Docker
|
||||
@@ -56,6 +65,11 @@ 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/heroku/Dockerfile.linux.amd64 --tag plugins/heroku .
|
||||
|
||||
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/gar/Dockerfile.linux.amd64 --tag plugins/gar .
|
||||
```
|
||||
|
||||
## Usage
|
||||
@@ -122,17 +136,35 @@ type: docker
|
||||
|
||||
steps:
|
||||
- name: push-to-gar
|
||||
image: plugins/gcr
|
||||
image: plugins/gar
|
||||
pull: never
|
||||
settings:
|
||||
tag: latest
|
||||
repo: project-id/repo/image-name
|
||||
registry_type: GAR
|
||||
location: us
|
||||
json_key:
|
||||
from_secret: gcr_json_key
|
||||
```
|
||||
|
||||
### GAR (Google Artifact Registry) using workload identity (OIDC)
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: push-to-gar
|
||||
image: plugins/gar
|
||||
pull: never
|
||||
settings:
|
||||
tag: latest
|
||||
repo: project-id/repo/image-name
|
||||
location: europe
|
||||
project_number: project-number
|
||||
pool_id: workload identity pool id
|
||||
provider_id: workload identity provider id
|
||||
service_account_email: service account email
|
||||
oidc_token_id:
|
||||
from_secret: token
|
||||
```
|
||||
|
||||
## Developer Notes
|
||||
|
||||
- When updating the base image, you will need to update for each architecture and OS.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CustomStringSliceFlag is like a regular StringSlice flag but with
|
||||
// semicolon as a delimiter
|
||||
type CustomStringSliceFlag struct {
|
||||
Value []string
|
||||
}
|
||||
|
||||
func (f *CustomStringSliceFlag) GetValue() []string {
|
||||
if f.Value == nil {
|
||||
return make([]string, 0)
|
||||
}
|
||||
return f.Value
|
||||
}
|
||||
|
||||
func (f *CustomStringSliceFlag) String() string {
|
||||
if f.Value == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.Join(f.Value, ";")
|
||||
}
|
||||
|
||||
func (f *CustomStringSliceFlag) Set(v string) error {
|
||||
for _, s := range strings.Split(v, ";") {
|
||||
s = strings.TrimSpace(s)
|
||||
f.Value = append(f.Value, s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
+68
-31
@@ -151,6 +151,17 @@ func main() {
|
||||
Usage: "build args",
|
||||
EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV",
|
||||
},
|
||||
cli.GenericFlag{
|
||||
Name: "args-new",
|
||||
Usage: "build args new",
|
||||
EnvVar: "PLUGIN_BUILD_ARGS_NEW",
|
||||
Value: new(CustomStringSliceFlag),
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "plugin-multiple-build-agrs",
|
||||
Usage: "plugin multiple build agrs",
|
||||
EnvVar: "PLUGIN_MULTIPLE_BUILD_ARGS",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
Name: "quiet",
|
||||
Usage: "quiet docker build",
|
||||
@@ -222,6 +233,21 @@ func main() {
|
||||
Usage: "docker password",
|
||||
EnvVar: "PLUGIN_PASSWORD,DOCKER_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimageusername",
|
||||
Usage: "Docker username for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_USERNAME,PLUGIN_BASE_IMAGE_USERNAME,DOCKER_BASE_IMAGE_USERNAME",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimagepassword",
|
||||
Usage: "Docker password for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_PASSWORD,PLUGIN_BASE_IMAGE_PASSWORD,DOCKER_BASE_IMAGE_PASSWORD",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.baseimageregistry",
|
||||
Usage: "Docker registry for base image registry",
|
||||
EnvVar: "PLUGIN_DOCKER_REGISTRY,PLUGIN_BASE_IMAGE_REGISTRY,DOCKER_BASE_IMAGE_REGISTRY",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "docker.email",
|
||||
Usage: "docker email",
|
||||
@@ -292,6 +318,11 @@ func main() {
|
||||
Usage: "registry type",
|
||||
EnvVar: "PLUGIN_REGISTRY_TYPE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "access-token",
|
||||
Usage: "access token",
|
||||
EnvVar: "ACCESS_TOKEN",
|
||||
},
|
||||
}
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
@@ -309,41 +340,44 @@ func run(c *cli.Context) error {
|
||||
Dryrun: c.Bool("dry-run"),
|
||||
Cleanup: c.BoolT("docker.purge"),
|
||||
Login: docker.Login{
|
||||
Registry: c.String("docker.registry"),
|
||||
Username: c.String("docker.username"),
|
||||
Password: c.String("docker.password"),
|
||||
Email: c.String("docker.email"),
|
||||
Config: c.String("docker.config"),
|
||||
Registry: c.String("docker.registry"),
|
||||
Username: c.String("docker.username"),
|
||||
Password: c.String("docker.password"),
|
||||
Email: c.String("docker.email"),
|
||||
Config: c.String("docker.config"),
|
||||
AccessToken: c.String("access-token"),
|
||||
},
|
||||
CardPath: c.String("drone-card-path"),
|
||||
ArtifactFile: c.String("artifact-file"),
|
||||
Build: docker.Build{
|
||||
Remote: c.String("remote.url"),
|
||||
Name: c.String("commit.sha"),
|
||||
TempTag: generateTempTag(),
|
||||
Dockerfile: c.String("dockerfile"),
|
||||
Context: c.String("context"),
|
||||
Tags: c.StringSlice("tags"),
|
||||
Args: c.StringSlice("args"),
|
||||
ArgsEnv: c.StringSlice("args-from-env"),
|
||||
Target: c.String("target"),
|
||||
Squash: c.Bool("squash"),
|
||||
Pull: c.BoolT("pull-image"),
|
||||
CacheFrom: c.StringSlice("cache-from"),
|
||||
Compress: c.Bool("compress"),
|
||||
Repo: c.String("repo"),
|
||||
Labels: c.StringSlice("custom-labels"),
|
||||
LabelSchema: c.StringSlice("label-schema"),
|
||||
AutoLabel: c.BoolT("auto-label"),
|
||||
Link: c.String("link"),
|
||||
NoCache: c.Bool("no-cache"),
|
||||
Secret: c.String("secret"),
|
||||
SecretEnvs: c.StringSlice("secrets-from-env"),
|
||||
SecretFiles: c.StringSlice("secrets-from-file"),
|
||||
AddHost: c.StringSlice("add-host"),
|
||||
Quiet: c.Bool("quiet"),
|
||||
Platform: c.String("platform"),
|
||||
SSHAgentKey: c.String("ssh-agent-key"),
|
||||
Remote: c.String("remote.url"),
|
||||
Name: c.String("commit.sha"),
|
||||
TempTag: generateTempTag(),
|
||||
Dockerfile: c.String("dockerfile"),
|
||||
Context: c.String("context"),
|
||||
Tags: c.StringSlice("tags"),
|
||||
Args: c.StringSlice("args"),
|
||||
ArgsEnv: c.StringSlice("args-from-env"),
|
||||
ArgsNew: c.Generic("args-new").(*CustomStringSliceFlag).GetValue(),
|
||||
IsMultipleBuildArgs: c.Bool("plugin-multiple-build-agrs"),
|
||||
Target: c.String("target"),
|
||||
Squash: c.Bool("squash"),
|
||||
Pull: c.BoolT("pull-image"),
|
||||
CacheFrom: c.StringSlice("cache-from"),
|
||||
Compress: c.Bool("compress"),
|
||||
Repo: c.String("repo"),
|
||||
Labels: c.StringSlice("custom-labels"),
|
||||
LabelSchema: c.StringSlice("label-schema"),
|
||||
AutoLabel: c.BoolT("auto-label"),
|
||||
Link: c.String("link"),
|
||||
NoCache: c.Bool("no-cache"),
|
||||
Secret: c.String("secret"),
|
||||
SecretEnvs: c.StringSlice("secrets-from-env"),
|
||||
SecretFiles: c.StringSlice("secrets-from-file"),
|
||||
AddHost: c.StringSlice("add-host"),
|
||||
Quiet: c.Bool("quiet"),
|
||||
Platform: c.String("platform"),
|
||||
SSHAgentKey: c.String("ssh-agent-key"),
|
||||
},
|
||||
Daemon: docker.Daemon{
|
||||
Registry: c.String("docker.registry"),
|
||||
@@ -361,6 +395,9 @@ func run(c *cli.Context) error {
|
||||
Experimental: c.Bool("daemon.experimental"),
|
||||
RegistryType: registryType,
|
||||
},
|
||||
BaseImageRegistry: c.String("docker.baseimageregistry"),
|
||||
BaseImageUsername: c.String("docker.baseimageusername"),
|
||||
BaseImagePassword: c.String("docker.baseimagepassword"),
|
||||
}
|
||||
|
||||
if c.Bool("tags.auto") {
|
||||
|
||||
+84
-14
@@ -22,6 +22,10 @@ import (
|
||||
docker "github.com/drone-plugins/drone-docker"
|
||||
)
|
||||
|
||||
type ecrAPI interface {
|
||||
DescribeImages(*ecr.DescribeImagesInput) (*ecr.DescribeImagesOutput, error)
|
||||
}
|
||||
|
||||
const defaultRegion = "us-east-1"
|
||||
|
||||
func main() {
|
||||
@@ -31,17 +35,19 @@ func main() {
|
||||
}
|
||||
|
||||
var (
|
||||
repo = getenv("PLUGIN_REPO")
|
||||
registry = getenv("PLUGIN_REGISTRY")
|
||||
region = getenv("PLUGIN_REGION", "ECR_REGION", "AWS_REGION")
|
||||
key = getenv("PLUGIN_ACCESS_KEY", "ECR_ACCESS_KEY", "AWS_ACCESS_KEY_ID")
|
||||
secret = getenv("PLUGIN_SECRET_KEY", "ECR_SECRET_KEY", "AWS_SECRET_ACCESS_KEY")
|
||||
create = parseBoolOrDefault(false, getenv("PLUGIN_CREATE_REPOSITORY", "ECR_CREATE_REPOSITORY"))
|
||||
lifecyclePolicy = getenv("PLUGIN_LIFECYCLE_POLICY")
|
||||
repositoryPolicy = getenv("PLUGIN_REPOSITORY_POLICY")
|
||||
assumeRole = getenv("PLUGIN_ASSUME_ROLE")
|
||||
externalId = getenv("PLUGIN_EXTERNAL_ID")
|
||||
scanOnPush = parseBoolOrDefault(false, getenv("PLUGIN_SCAN_ON_PUSH"))
|
||||
repo = getenv("PLUGIN_REPO")
|
||||
registry = getenv("PLUGIN_REGISTRY")
|
||||
region = getenv("PLUGIN_REGION", "ECR_REGION", "AWS_REGION")
|
||||
key = getenv("PLUGIN_ACCESS_KEY", "ECR_ACCESS_KEY", "AWS_ACCESS_KEY_ID")
|
||||
secret = getenv("PLUGIN_SECRET_KEY", "ECR_SECRET_KEY", "AWS_SECRET_ACCESS_KEY")
|
||||
create = parseBoolOrDefault(false, getenv("PLUGIN_CREATE_REPOSITORY", "ECR_CREATE_REPOSITORY"))
|
||||
lifecyclePolicy = getenv("PLUGIN_LIFECYCLE_POLICY")
|
||||
repositoryPolicy = getenv("PLUGIN_REPOSITORY_POLICY")
|
||||
assumeRole = getenv("PLUGIN_ASSUME_ROLE")
|
||||
externalId = getenv("PLUGIN_EXTERNAL_ID")
|
||||
scanOnPush = parseBoolOrDefault(false, getenv("PLUGIN_SCAN_ON_PUSH"))
|
||||
idToken = os.Getenv("PLUGIN_OIDC_TOKEN_ID")
|
||||
skipPushIfTagExists = parseBoolOrDefault(false, getenv("PLUGIN_SKIP_PUSH_IF_TAG_EXISTS"))
|
||||
)
|
||||
|
||||
// set the region
|
||||
@@ -61,7 +67,7 @@ func main() {
|
||||
log.Fatal(fmt.Sprintf("error creating aws session: %v", err))
|
||||
}
|
||||
|
||||
svc := getECRClient(sess, assumeRole, externalId)
|
||||
svc := getECRClient(sess, assumeRole, externalId, idToken)
|
||||
username, password, defaultRegistry, err := getAuthInfo(svc)
|
||||
|
||||
if registry == "" {
|
||||
@@ -113,6 +119,34 @@ func main() {
|
||||
os.Setenv("DOCKER_PASSWORD", password)
|
||||
os.Setenv("PLUGIN_REGISTRY_TYPE", "ECR")
|
||||
|
||||
// Skip if tag already exits for both mutable and immutable repos
|
||||
if skipPushIfTagExists {
|
||||
tagInput := getenv("PLUGIN_TAG", "PLUGIN_TAGS")
|
||||
var tags []string
|
||||
if tagInput == "" {
|
||||
tags = []string{"latest"}
|
||||
} else {
|
||||
for _, t := range strings.Split(tagInput, ",") {
|
||||
trimmed := strings.TrimSpace(t)
|
||||
if trimmed != "" {
|
||||
tags = append(tags, trimmed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositoryName := trimHostname(repo, registry)
|
||||
for _, t := range tags {
|
||||
exists, err := tagExists(svc, repositoryName, t)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error checking if image exists for tag %s: %v", t, err)
|
||||
}
|
||||
if exists {
|
||||
logrus.Infof("%s:%s: Image tag exists. Skipping push.", repo, t)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// invoke the base docker plugin binary
|
||||
cmd := exec.Command(docker.GetDroneDockerExecCmd())
|
||||
cmd.Stdout = os.Stdout
|
||||
@@ -213,11 +247,30 @@ func getenv(key ...string) (s string) {
|
||||
return
|
||||
}
|
||||
|
||||
func getECRClient(sess *session.Session, role string, externalId string) *ecr.ECR {
|
||||
func getECRClient(sess *session.Session, role string, externalId string, idToken string) *ecr.ECR {
|
||||
if role == "" {
|
||||
return ecr.New(sess)
|
||||
}
|
||||
if externalId != "" {
|
||||
|
||||
if idToken != "" {
|
||||
tempFile, err := os.CreateTemp("/tmp", "idToken-*.jwt")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create temporary file: %v", err)
|
||||
}
|
||||
defer tempFile.Close()
|
||||
|
||||
if err := os.Chmod(tempFile.Name(), 0600); err != nil {
|
||||
log.Fatalf("Failed to set file permissions: %v", err)
|
||||
}
|
||||
|
||||
if _, err := tempFile.WriteString(idToken); err != nil {
|
||||
log.Fatalf("Failed to write ID token to temporary file: %v", err)
|
||||
}
|
||||
|
||||
// Create credentials using the path to the ID token file
|
||||
creds := stscreds.NewWebIdentityCredentials(sess, role, "", tempFile.Name())
|
||||
return ecr.New(sess, &aws.Config{Credentials: creds})
|
||||
} else if externalId != "" {
|
||||
return ecr.New(sess, &aws.Config{
|
||||
Credentials: stscreds.NewCredentials(sess, role, func(p *stscreds.AssumeRoleProvider) {
|
||||
p.ExternalID = &externalId
|
||||
@@ -229,3 +282,20 @@ func getECRClient(sess *session.Session, role string, externalId string) *ecr.EC
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func tagExists(svc ecrAPI, repository, tag string) (bool, error) {
|
||||
input := &ecr.DescribeImagesInput{
|
||||
RepositoryName: aws.String(repository),
|
||||
ImageIds: []*ecr.ImageIdentifier{
|
||||
{ImageTag: aws.String(tag)},
|
||||
},
|
||||
}
|
||||
output, err := svc.DescribeImages(input)
|
||||
if err != nil {
|
||||
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == "ImageNotFoundException" {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return len(output.ImageDetails) > 0, nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
docker "github.com/drone-plugins/drone-docker"
|
||||
"github.com/drone-plugins/drone-docker/internal/gcp"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/oauth2/google"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Repo string
|
||||
Registry string
|
||||
Password string
|
||||
WorkloadIdentity bool
|
||||
Username string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
type staticTokenSource struct {
|
||||
token *oauth2.Token
|
||||
}
|
||||
|
||||
func (s *staticTokenSource) Token() (*oauth2.Token, error) {
|
||||
return s.token, nil
|
||||
}
|
||||
|
||||
func loadConfig() Config {
|
||||
// Default username
|
||||
username := "_json_key"
|
||||
var config Config
|
||||
|
||||
// Load env-file if it exists
|
||||
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
|
||||
if err := godotenv.Load(env); err != nil {
|
||||
log.Fatalf("Error loading .env file: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
idToken := getenv("PLUGIN_OIDC_TOKEN_ID")
|
||||
projectId := getenv("PLUGIN_PROJECT_NUMBER")
|
||||
poolId := getenv("PLUGIN_POOL_ID")
|
||||
providerId := getenv("PLUGIN_PROVIDER_ID")
|
||||
serviceAccountEmail := getenv("PLUGIN_SERVICE_ACCOUNT_EMAIL")
|
||||
|
||||
if idToken != "" && projectId != "" && poolId != "" && providerId != "" && serviceAccountEmail != "" {
|
||||
federalToken, err := gcp.GetFederalToken(idToken, projectId, poolId, providerId)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error (getFederalToken): %s", err)
|
||||
}
|
||||
accessToken, err := gcp.GetGoogleCloudAccessToken(federalToken, serviceAccountEmail)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error (getGoogleCloudAccessToken): %s", err)
|
||||
}
|
||||
config.AccessToken = accessToken
|
||||
} else {
|
||||
password := getenv(
|
||||
"PLUGIN_JSON_KEY",
|
||||
"GCR_JSON_KEY",
|
||||
"GOOGLE_CREDENTIALS",
|
||||
"TOKEN",
|
||||
)
|
||||
config.WorkloadIdentity = parseBoolOrDefault(false, getenv("PLUGIN_WORKLOAD_IDENTITY"))
|
||||
config.Username, config.Password = setUsernameAndPassword(username, password, config.WorkloadIdentity)
|
||||
}
|
||||
|
||||
location := getenv("PLUGIN_LOCATION")
|
||||
repo := getenv("PLUGIN_REPO")
|
||||
|
||||
registry := getenv("PLUGIN_REGISTRY")
|
||||
if registry == "" {
|
||||
registry = fmt.Sprintf("%s-docker.pkg.dev", location)
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(repo, registry) {
|
||||
repo = path.Join(registry, repo)
|
||||
}
|
||||
config.Repo = repo
|
||||
config.Registry = registry
|
||||
return config
|
||||
}
|
||||
|
||||
func main() {
|
||||
config := loadConfig()
|
||||
if config.AccessToken != "" {
|
||||
os.Setenv("ACCESS_TOKEN", config.AccessToken)
|
||||
} else if config.Username != "" && config.Password != "" {
|
||||
os.Setenv("DOCKER_USERNAME", config.Username)
|
||||
os.Setenv("DOCKER_PASSWORD", config.Password)
|
||||
}
|
||||
|
||||
os.Setenv("PLUGIN_REPO", config.Repo)
|
||||
os.Setenv("PLUGIN_REGISTRY", config.Registry)
|
||||
|
||||
// invoke the base docker plugin binary
|
||||
cmd := exec.Command(docker.GetDroneDockerExecCmd())
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getOauthToken(data []byte) (s string) {
|
||||
scopes := []string{
|
||||
"https://www.googleapis.com/auth/cloud-platform",
|
||||
}
|
||||
ctx := context.Background()
|
||||
credentials, err := google.CredentialsFromJSON(ctx, data, scopes...)
|
||||
if err == nil {
|
||||
token, err := credentials.TokenSource.Token()
|
||||
if err == nil {
|
||||
return token.AccessToken
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func setUsernameAndPassword(user string, pass string, workloadIdentity bool) (u string, p string) {
|
||||
// decode the token if base64 encoded
|
||||
decoded, err := base64.StdEncoding.DecodeString(pass)
|
||||
if err == nil {
|
||||
pass = string(decoded)
|
||||
}
|
||||
// get oauth token and set username if using workload identity
|
||||
if workloadIdentity {
|
||||
data := []byte(pass)
|
||||
pass = getOauthToken(data)
|
||||
user = "oauth2accesstoken"
|
||||
}
|
||||
return user, pass
|
||||
}
|
||||
|
||||
func parseBoolOrDefault(defaultValue bool, s string) (result bool) {
|
||||
var err error
|
||||
result, err = strconv.ParseBool(s)
|
||||
if err != nil {
|
||||
result = defaultValue
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func getenv(key ...string) (s string) {
|
||||
for _, k := range key {
|
||||
s = os.Getenv(k)
|
||||
if s != "" {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
+42
-38
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -11,11 +10,12 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
docker "github.com/drone-plugins/drone-docker"
|
||||
"github.com/drone-plugins/drone-docker/internal/gcp"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/oauth2/google"
|
||||
|
||||
docker "github.com/drone-plugins/drone-docker"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
@@ -24,12 +24,13 @@ type Config struct {
|
||||
Password string
|
||||
WorkloadIdentity bool
|
||||
Username string
|
||||
RegistryType string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
func loadConfig() Config {
|
||||
// Default username
|
||||
username := "_json_key"
|
||||
var config Config
|
||||
|
||||
// Load env-file if it exists
|
||||
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
|
||||
@@ -38,18 +39,34 @@ func loadConfig() Config {
|
||||
}
|
||||
}
|
||||
|
||||
location := getenv("PLUGIN_LOCATION")
|
||||
idToken := getenv("PLUGIN_OIDC_TOKEN_ID")
|
||||
projectId := getenv("PLUGIN_PROJECT_NUMBER")
|
||||
poolId := getenv("PLUGIN_POOL_ID")
|
||||
providerId := getenv("PLUGIN_PROVIDER_ID")
|
||||
serviceAccountEmail := getenv("PLUGIN_SERVICE_ACCOUNT_EMAIL")
|
||||
|
||||
if idToken != "" && projectId != "" && poolId != "" && providerId != "" && serviceAccountEmail != "" {
|
||||
federalToken, err := gcp.GetFederalToken(idToken, projectId, poolId, providerId)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error (getFederalToken): %s", err)
|
||||
}
|
||||
accessToken, err := gcp.GetGoogleCloudAccessToken(federalToken, serviceAccountEmail)
|
||||
if err != nil {
|
||||
logrus.Fatalf("Error (getGoogleCloudAccessToken): %s", err)
|
||||
}
|
||||
config.AccessToken = accessToken
|
||||
} else {
|
||||
password := getenv(
|
||||
"PLUGIN_JSON_KEY",
|
||||
"GCR_JSON_KEY",
|
||||
"GOOGLE_CREDENTIALS",
|
||||
"TOKEN",
|
||||
)
|
||||
config.WorkloadIdentity = parseBoolOrDefault(false, getenv("PLUGIN_WORKLOAD_IDENTITY"))
|
||||
config.Username, config.Password = setUsernameAndPassword(username, password, config.WorkloadIdentity)
|
||||
}
|
||||
|
||||
repo := getenv("PLUGIN_REPO")
|
||||
|
||||
password := getenv(
|
||||
"PLUGIN_JSON_KEY",
|
||||
"GCR_JSON_KEY",
|
||||
"GOOGLE_CREDENTIALS",
|
||||
"TOKEN",
|
||||
)
|
||||
workloadIdentity := parseBoolOrDefault(false, getenv("PLUGIN_WORKLOAD_IDENTITY"))
|
||||
username, password = setUsernameAndPassword(username, password, workloadIdentity)
|
||||
|
||||
registryType := getenv("PLUGIN_REGISTRY_TYPE")
|
||||
if registryType == "" {
|
||||
registryType = "GCR"
|
||||
@@ -57,41 +74,28 @@ func loadConfig() Config {
|
||||
|
||||
registry := getenv("PLUGIN_REGISTRY")
|
||||
if registry == "" {
|
||||
switch registryType {
|
||||
case "GCR":
|
||||
registry = "gcr.io"
|
||||
case "GAR":
|
||||
if location == "" {
|
||||
logrus.Fatalf("Error: For REGISTRY_TYPE of GAR, LOCATION must be set")
|
||||
}
|
||||
registry = fmt.Sprintf("%s-docker.pkg.dev", location)
|
||||
default:
|
||||
logrus.Fatalf("Unsupported registry type: %s", registryType)
|
||||
}
|
||||
registry = "gcr.io"
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(repo, registry) {
|
||||
repo = path.Join(registry, repo)
|
||||
}
|
||||
|
||||
return Config{
|
||||
Repo: repo,
|
||||
Registry: registry,
|
||||
Password: password,
|
||||
WorkloadIdentity: workloadIdentity,
|
||||
Username: username,
|
||||
RegistryType: registryType,
|
||||
}
|
||||
config.Repo = repo
|
||||
config.Registry = registry
|
||||
return config
|
||||
}
|
||||
|
||||
func main() {
|
||||
config := loadConfig()
|
||||
if config.AccessToken != "" {
|
||||
os.Setenv("ACCESS_TOKEN", config.AccessToken)
|
||||
} else if config.Username != "" && config.Password != "" {
|
||||
os.Setenv("DOCKER_USERNAME", config.Username)
|
||||
os.Setenv("DOCKER_PASSWORD", config.Password)
|
||||
}
|
||||
|
||||
os.Setenv("PLUGIN_REPO", config.Repo)
|
||||
os.Setenv("PLUGIN_REGISTRY", config.Registry)
|
||||
os.Setenv("DOCKER_USERNAME", config.Username)
|
||||
os.Setenv("DOCKER_PASSWORD", config.Password)
|
||||
os.Setenv("PLUGIN_REGISTRY_TYPE", config.RegistryType)
|
||||
|
||||
// invoke the base docker plugin binary
|
||||
cmd := exec.Command(docker.GetDroneDockerExecCmd())
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/drone-plugins/drone-docker/internal/docker"
|
||||
"github.com/drone-plugins/drone-plugin-lib/drone"
|
||||
)
|
||||
|
||||
@@ -34,53 +35,59 @@ type (
|
||||
|
||||
// Login defines Docker login parameters.
|
||||
Login struct {
|
||||
Registry string // Docker registry address
|
||||
Username string // Docker registry username
|
||||
Password string // Docker registry password
|
||||
Email string // Docker registry email
|
||||
Config string // Docker Auth Config
|
||||
Registry string // Docker registry address
|
||||
Username string // Docker registry username
|
||||
Password string // Docker registry password
|
||||
Email string // Docker registry email
|
||||
Config string // Docker Auth Config
|
||||
AccessToken string // External Access Token
|
||||
}
|
||||
|
||||
// Build defines Docker build parameters.
|
||||
Build struct {
|
||||
Remote string // Git remote URL
|
||||
Name string // Docker build using default named tag
|
||||
TempTag string // Temporary tag used during docker build
|
||||
Dockerfile string // Docker build Dockerfile
|
||||
Context string // Docker build context
|
||||
Tags []string // Docker build tags
|
||||
Args []string // Docker build args
|
||||
ArgsEnv []string // Docker build args from env
|
||||
Target string // Docker build target
|
||||
Squash bool // Docker build squash
|
||||
Pull bool // Docker build pull
|
||||
CacheFrom []string // Docker build cache-from
|
||||
Compress bool // Docker build compress
|
||||
Repo string // Docker build repository
|
||||
LabelSchema []string // label-schema Label map
|
||||
AutoLabel bool // auto-label bool
|
||||
Labels []string // Label map
|
||||
Link string // Git repo link
|
||||
NoCache bool // Docker build no-cache
|
||||
Secret string // secret keypair
|
||||
SecretEnvs []string // Docker build secrets with env var as source
|
||||
SecretFiles []string // Docker build secrets with file as source
|
||||
AddHost []string // Docker build add-host
|
||||
Quiet bool // Docker build quiet
|
||||
Platform string // Docker build platform
|
||||
SSHAgentKey string // Docker build ssh agent key
|
||||
SSHKeyPath string // Docker build ssh key path
|
||||
Remote string // Git remote URL
|
||||
Name string // Docker build using default named tag
|
||||
TempTag string // Temporary tag used during docker build
|
||||
Dockerfile string // Docker build Dockerfile
|
||||
Context string // Docker build context
|
||||
Tags []string // Docker build tags
|
||||
Args []string // Docker build args
|
||||
ArgsEnv []string // Docker build args from env
|
||||
ArgsNew []string // docker build args which has comma seperated values
|
||||
IsMultipleBuildArgs bool // env variable for fall back to old build args
|
||||
Target string // Docker build target
|
||||
Squash bool // Docker build squash
|
||||
Pull bool // Docker build pull
|
||||
CacheFrom []string // Docker build cache-from
|
||||
Compress bool // Docker build compress
|
||||
Repo string // Docker build repository
|
||||
LabelSchema []string // label-schema Label map
|
||||
AutoLabel bool // auto-label bool
|
||||
Labels []string // Label map
|
||||
Link string // Git repo link
|
||||
NoCache bool // Docker build no-cache
|
||||
Secret string // secret keypair
|
||||
SecretEnvs []string // Docker build secrets with env var as source
|
||||
SecretFiles []string // Docker build secrets with file as source
|
||||
AddHost []string // Docker build add-host
|
||||
Quiet bool // Docker build quiet
|
||||
Platform string // Docker build platform
|
||||
SSHAgentKey string // Docker build ssh agent key
|
||||
SSHKeyPath string // Docker build ssh key path
|
||||
}
|
||||
|
||||
// Plugin defines the Docker plugin parameters.
|
||||
Plugin struct {
|
||||
Login Login // Docker login configuration
|
||||
Build Build // Docker build configuration
|
||||
Daemon Daemon // Docker daemon configuration
|
||||
Dryrun bool // Docker push is skipped
|
||||
Cleanup bool // Docker purge is enabled
|
||||
CardPath string // Card path to write file to
|
||||
ArtifactFile string // Artifact path to write file to
|
||||
Login Login // Docker login configuration
|
||||
Build Build // Docker build configuration
|
||||
Daemon Daemon // Docker daemon configuration
|
||||
Dryrun bool // Docker push is skipped
|
||||
Cleanup bool // Docker purge is enabled
|
||||
CardPath string // Card path to write file to
|
||||
ArtifactFile string // Artifact path to write file to
|
||||
BaseImageRegistry string // Docker registry to pull base image
|
||||
BaseImageUsername string // Docker registry username to pull base image
|
||||
BaseImagePassword string // Docker registry password to pull base image
|
||||
}
|
||||
|
||||
Card []struct {
|
||||
@@ -113,7 +120,6 @@ type (
|
||||
|
||||
// Exec executes the plugin step
|
||||
func (p Plugin) Exec() error {
|
||||
|
||||
// start the Docker daemon server
|
||||
if !p.Daemon.Disabled {
|
||||
p.startDaemon()
|
||||
@@ -143,6 +149,8 @@ func (p Plugin) Exec() error {
|
||||
fmt.Println("Detected registry credentials")
|
||||
case p.Login.Config != "":
|
||||
fmt.Println("Detected registry credentials file")
|
||||
case p.Login.AccessToken != "":
|
||||
fmt.Println("Detected access token")
|
||||
default:
|
||||
fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
|
||||
}
|
||||
@@ -158,6 +166,35 @@ func (p Plugin) Exec() error {
|
||||
}
|
||||
}
|
||||
|
||||
// instead of writing to config file directly, using docker's login func
|
||||
// is better to integrate with various credential helpers,
|
||||
// it also handles different registry specific logic in a better way,
|
||||
// as opposed to config write where different registries need to be addressed differently.
|
||||
// It handles any changes in the authentication process across different Docker versions.
|
||||
|
||||
if p.BaseImageRegistry != "" {
|
||||
if p.BaseImageUsername == "" {
|
||||
fmt.Printf("Username cannot be empty. The base image connector requires authenticated access. Please either use an authenticated connector, or remove the base image connector.")
|
||||
}
|
||||
if p.BaseImagePassword == "" {
|
||||
fmt.Printf("Password cannot be empty. The base image connector requires authenticated access. Please either use an authenticated connector, or remove the base image connector.")
|
||||
}
|
||||
var baseConnectorLogin Login
|
||||
baseConnectorLogin.Registry = p.BaseImageRegistry
|
||||
baseConnectorLogin.Username = p.BaseImageUsername
|
||||
baseConnectorLogin.Password = p.BaseImagePassword
|
||||
|
||||
cmd := commandLogin(baseConnectorLogin)
|
||||
|
||||
raw, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
out := string(raw)
|
||||
out = strings.Replace(out, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.", "", -1)
|
||||
fmt.Println(out)
|
||||
return fmt.Errorf("Error authenticating base connector: exit status 1")
|
||||
}
|
||||
}
|
||||
|
||||
// login to the Docker registry
|
||||
if p.Login.Password != "" {
|
||||
cmd := commandLogin(p.Login)
|
||||
@@ -166,7 +203,18 @@ func (p Plugin) Exec() error {
|
||||
out := string(raw)
|
||||
out = strings.Replace(out, "WARNING! Using --password via the CLI is insecure. Use --password-stdin.", "", -1)
|
||||
fmt.Println(out)
|
||||
return fmt.Errorf("Error authenticating: exit status 1")
|
||||
return fmt.Errorf("error authenticating: exit status 1")
|
||||
}
|
||||
} else if p.Login.AccessToken != "" {
|
||||
cmd := commandLoginAccessToken(p.Login, p.Login.AccessToken)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error logging in to Docker registry: %s", err)
|
||||
}
|
||||
if strings.Contains(string(output), "Login Succeeded") {
|
||||
fmt.Println("Login successful")
|
||||
} else {
|
||||
return fmt.Errorf("login did not succeed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,6 +305,35 @@ func (p Plugin) Exec() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// helper function to set the credentials
|
||||
func setDockerAuth(username, password, registry, baseImageUsername,
|
||||
baseImagePassword, baseImageRegistry string) ([]byte, error) {
|
||||
var credentials []docker.RegistryCredentials
|
||||
// add only docker registry to the config
|
||||
dockerConfig := docker.NewConfig()
|
||||
if password != "" {
|
||||
pushToRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: registry,
|
||||
Username: username,
|
||||
Password: password,
|
||||
}
|
||||
// push registry auth
|
||||
credentials = append(credentials, pushToRegistryCreds)
|
||||
}
|
||||
|
||||
if baseImageRegistry != "" {
|
||||
pullFromRegistryCreds := docker.RegistryCredentials{
|
||||
Registry: baseImageRegistry,
|
||||
Username: baseImageUsername,
|
||||
Password: baseImagePassword,
|
||||
}
|
||||
// base image registry auth
|
||||
credentials = append(credentials, pullFromRegistryCreds)
|
||||
}
|
||||
// Creates docker config for both the registries used for authentication
|
||||
return dockerConfig.CreateDockerConfigJson(credentials)
|
||||
}
|
||||
|
||||
// helper function to create the docker login command.
|
||||
func commandLogin(login Login) *exec.Cmd {
|
||||
if login.Email != "" {
|
||||
@@ -270,6 +347,17 @@ func commandLogin(login Login) *exec.Cmd {
|
||||
)
|
||||
}
|
||||
|
||||
func commandLoginAccessToken(login Login, accessToken string) *exec.Cmd {
|
||||
cmd := exec.Command(dockerExe,
|
||||
"login",
|
||||
"-u",
|
||||
"oauth2accesstoken",
|
||||
"--password-stdin",
|
||||
login.Registry)
|
||||
cmd.Stdin = strings.NewReader(accessToken)
|
||||
return cmd
|
||||
}
|
||||
|
||||
// helper to check if args match "docker pull <image>"
|
||||
func isCommandPull(args []string) bool {
|
||||
return len(args) > 2 && args[1] == "pull"
|
||||
@@ -327,8 +415,14 @@ func commandBuild(build Build) *exec.Cmd {
|
||||
for _, arg := range build.ArgsEnv {
|
||||
addProxyValue(&build, arg)
|
||||
}
|
||||
for _, arg := range build.Args {
|
||||
args = append(args, "--build-arg", arg)
|
||||
if build.IsMultipleBuildArgs {
|
||||
for _, arg := range build.ArgsNew {
|
||||
args = append(args, "--build-arg", arg)
|
||||
}
|
||||
} else {
|
||||
for _, arg := range build.Args {
|
||||
args = append(args, "--build-arg", arg)
|
||||
}
|
||||
}
|
||||
for _, host := range build.AddHost {
|
||||
args = append(args, "--add-host", host)
|
||||
@@ -433,6 +527,10 @@ func addProxyValue(build *Build, key string) {
|
||||
build.Args = append(build.Args, fmt.Sprintf("%s=%s", key, value))
|
||||
build.Args = append(build.Args, fmt.Sprintf("%s=%s", strings.ToUpper(key), value))
|
||||
}
|
||||
if len(value) > 0 && !hasProxyBuildArgNew(build, key) {
|
||||
build.ArgsNew = append(build.ArgsNew, fmt.Sprintf("%s=%s", key, value))
|
||||
build.ArgsNew = append(build.ArgsNew, fmt.Sprintf("%s=%s", strings.ToUpper(key), value))
|
||||
}
|
||||
}
|
||||
|
||||
// helper function to get a proxy value from the environment.
|
||||
@@ -460,6 +558,17 @@ func hasProxyBuildArg(build *Build, key string) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
func hasProxyBuildArgNew(build *Build, key string) bool {
|
||||
keyUpper := strings.ToUpper(key)
|
||||
|
||||
for _, s := range build.ArgsNew {
|
||||
if strings.HasPrefix(s, key) || strings.HasPrefix(s, keyUpper) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// helper function to create the docker tag command.
|
||||
func commandTag(build Build, tag string) *exec.Cmd {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
FROM plugins/docker:linux-amd64
|
||||
|
||||
ADD release/linux/amd64/drone-gar /bin/
|
||||
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-gar"]
|
||||
@@ -0,0 +1,4 @@
|
||||
FROM plugins/docker:linux-arm64
|
||||
|
||||
ADD release/linux/arm64/drone-gar /bin/
|
||||
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-gar"]
|
||||
@@ -0,0 +1,10 @@
|
||||
# escape=`
|
||||
FROM plugins/docker:windows-1809-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone GAR" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-gar.exe C:/bin/drone-gar.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-gar.exe" ]
|
||||
@@ -0,0 +1,10 @@
|
||||
# escape=`
|
||||
FROM plugins/docker:windows-ltsc2022-amd64
|
||||
|
||||
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
|
||||
org.label-schema.name="Drone GAR" `
|
||||
org.label-schema.vendor="Drone.IO Community" `
|
||||
org.label-schema.schema-version="1.0"
|
||||
|
||||
ADD release/windows/amd64/drone-gar.exe C:/bin/drone-gar.exe
|
||||
ENTRYPOINT [ "C:\\bin\\drone-gar.exe" ]
|
||||
@@ -0,0 +1,31 @@
|
||||
image: plugins/gar:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}
|
||||
{{#if build.tags}}
|
||||
tags:
|
||||
{{#each build.tags}}
|
||||
- {{this}}
|
||||
{{/each}}
|
||||
{{/if}}
|
||||
manifests:
|
||||
-
|
||||
image: plugins/gar:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: linux
|
||||
-
|
||||
image: plugins/gar:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64
|
||||
platform:
|
||||
architecture: arm64
|
||||
os: linux
|
||||
variant: v8
|
||||
-
|
||||
image: plugins/gar:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: 1809
|
||||
-
|
||||
image: plugins/gar:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-ltsc2022-amd64
|
||||
platform:
|
||||
architecture: amd64
|
||||
os: windows
|
||||
version: ltsc2022
|
||||
@@ -0,0 +1,8 @@
|
||||
This document explains on how to install certain git hooks globally for all repositories in your machine.
|
||||
|
||||
Step 1: git clone https://github.com/drone-plugins/drone-docker.git
|
||||
Step 2: cd git-hooks
|
||||
Step 3: Run install.sh
|
||||
|
||||
"install.sh" script will create .git_template in the user directory and will put the git hook and its dependent scripts in it. Along with the .git_template folder, it will add 2 sections "init" and "hooks boolean" in the .gitconfig file in the same user's root directory.
|
||||
After running "install.sh" if you create/clone a new git repository then all the hooks will get install automatically for the git repository. In case of existing git repository copy the contents of ~/.git_template/hooks into the .git/hooks directory of existing git repository.
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Helper script to be used as a pre-commit hook.
|
||||
|
||||
echo "This hook checks for any secrets getting pushed as part of commit. If you feel that scan is false positive. \
|
||||
Then add the exclusion in .gitleaksignore file. For more info visit: https://github.com/zricethezav/gitleaks"
|
||||
|
||||
GIT_LEAKS_PRE_COMMIT=s$(git config --bool hook.pre-commit.gitleak)
|
||||
|
||||
echo "INFO: Scanning Commits information for any GIT LEAKS"
|
||||
gitleaks protect --staged -v --exit-code=100
|
||||
STATUS=$?
|
||||
if [ $STATUS = 100 ]; then
|
||||
echo "WARNING: GIT LEAKS has detected sensitive information in your changes. Please remove them or add them (IF NON-SENSITIVE) in .gitleaksignore file."
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Helper script to be used as a pre-commit hook.
|
||||
|
||||
echo "This hook checks for any secrets getting pushed as part of commit. If you feel that scan is false positive. \
|
||||
Then add the exclusion in .gitleaksignore file. For more info visit: https://github.com/zricethezav/gitleaks"
|
||||
|
||||
GIT_LEAKS=$(git config --bool hook.pre-push.gitleaks)
|
||||
|
||||
echo "INFO: Scanning Commits information for any GIT LEAKS"
|
||||
gitleaks detect -s ./ --log-level=debug --log-opts=-1 -v
|
||||
STATUS=$?
|
||||
if [ $STATUS != 0 ]; then
|
||||
echo "WARNING: GIT LEAKS has detected sensitive information in your changes. Please remove them or add them (IF NON-SENSITIVE) in .gitleaksignore file."
|
||||
exit $STATUS
|
||||
else
|
||||
exit 0
|
||||
fi
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GL_SCRIPT_PATH="$HOME/.git_template/hooks/git-leaks-pre-commit.sh"
|
||||
|
||||
pushd `dirname $0` > /dev/null && cd ../.. && BASEDIR=$(pwd -L) && popd > /dev/null
|
||||
BASENAME=`basename $0`
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
#Initial commit : diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
GIT_LEAKS_PRE_COMMIT=hook.pre-commit.gitleaks
|
||||
if [ "`git config $GIT_LEAKS_PRE_COMMIT`" == "false" ]
|
||||
then
|
||||
echo -e '\033[0;31m' checking git leaks is disabled - to enable: '\033[0;37m'git config --unset $GIT_LEAKS_PRE_COMMIT '\033[0m'
|
||||
echo -e '\033[0;34m' checking git leaks ... to enable: '\033[0;37m'git config --add $GIT_LEAKS_PRE_COMMIT true '\033[0m'
|
||||
else
|
||||
echo -e '\033[0;34m' checking for git leaks...
|
||||
[ -f "${GL_SCRIPT_PATH}" ] && . ${GL_SCRIPT_PATH} || echo "ERROR: Hook Script Not Found..." && exit 404
|
||||
fi
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GL_SCRIPT_PATH="$HOME/.git_template/hooks/git-leaks.sh"
|
||||
|
||||
pushd `dirname $0` > /dev/null && cd ../.. && BASEDIR=$(pwd -L) && popd > /dev/null
|
||||
BASENAME=`basename $0`
|
||||
|
||||
if git rev-parse --verify HEAD >/dev/null 2>&1
|
||||
then
|
||||
against=HEAD
|
||||
else
|
||||
#Initial commit : diff against an empty tree object
|
||||
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
||||
fi
|
||||
|
||||
GIT_LEAKS=hook.pre-push.gitleaks
|
||||
if [ "`git config $GIT_LEAKS`" == "false" ]
|
||||
then
|
||||
echo -e '\033[0;31m' checking git leaks is disabled - to enable: '\033[0;37m'git config --unset $GIT_LEAKS '\033[0m'
|
||||
echo -e '\033[0;34m' checking git leaks ... to enable: '\033[0;37m'git config --add $GIT_LEAKS true '\033[0m'
|
||||
else
|
||||
echo -e '\033[0;34m' checking for git leaks...
|
||||
[ -f "${GL_SCRIPT_PATH}" ] && . ${GL_SCRIPT_PATH} || echo "ERROR: Hook Script Not Found..." && exit 404
|
||||
fi
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#Function to check if package is installed or not
|
||||
#args: $1: Name of the Package
|
||||
function check_package_installed() {
|
||||
LOCAL_PACKAGE_NAME=$1
|
||||
echo "Checking if $LOCAL_PACKAGE_NAME is installed or not..."
|
||||
brew list $LOCAL_PACKAGE_NAME
|
||||
if [ "$?" -eq 1 ];then
|
||||
echo "Installing $LOCAL_PACKAGE_NAME package..."
|
||||
brew install $LOCAL_PACKAGE_NAME
|
||||
fi
|
||||
}
|
||||
|
||||
function create_git_template() {
|
||||
cd $BASEDIR
|
||||
mkdir -p ~/.git_template/hooks
|
||||
git config --global init.templatedir ${GIT_TEMPLATE}
|
||||
git config --global --add $GIT_LEAKS true
|
||||
git config --global --add $GIT_LEAKS_PRE_COMMIT true
|
||||
find hooks/ -type f -exec cp "{}" ~/.git_template/hooks \;
|
||||
#cp -f hooks/* ~/.git_template/hooks
|
||||
cat ~/.gitconfig
|
||||
}
|
||||
|
||||
GIT_TEMPLATE="~/.git_template"
|
||||
GIT_LEAKS=hook.pre-push.gitleaks
|
||||
GIT_LEAKS_PRE_COMMIT=hook.pre-commit.gitleaks
|
||||
|
||||
pushd `dirname $0` && BASEDIR=$(pwd -L) && popd
|
||||
|
||||
echo This script will install hooks that run scripts that could be updated without notice.
|
||||
|
||||
while true; do
|
||||
read -p "Do you wish to install these hooks?" yn
|
||||
case $yn in
|
||||
[Yy]* ) check_package_installed "gitleaks";
|
||||
break;;
|
||||
[Nn]* ) exit;;
|
||||
* ) echo "Please answer yes or no.";;
|
||||
esac
|
||||
done
|
||||
|
||||
create_git_template
|
||||
@@ -9,22 +9,37 @@ require (
|
||||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743
|
||||
github.com/joho/godotenv v1.3.0
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/stretchr/testify v1.8.1
|
||||
github.com/urfave/cli v1.22.2
|
||||
golang.org/x/oauth2 v0.8.0
|
||||
golang.org/x/oauth2 v0.13.0
|
||||
google.golang.org/api v0.146.0
|
||||
)
|
||||
|
||||
require (
|
||||
cloud.google.com/go/compute/metadata v0.2.0 // indirect
|
||||
cloud.google.com/go/compute v1.23.1 // indirect
|
||||
cloud.google.com/go/compute/metadata v0.2.3 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/s2a-go v0.1.7 // indirect
|
||||
github.com/google/uuid v1.3.1 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.1 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
golang.org/x/net v0.10.0 // indirect
|
||||
golang.org/x/sys v0.8.0 // indirect
|
||||
google.golang.org/appengine v1.6.7 // indirect
|
||||
google.golang.org/protobuf v1.28.0 // indirect
|
||||
go.opencensus.io v0.24.0 // indirect
|
||||
golang.org/x/crypto v0.14.0 // indirect
|
||||
golang.org/x/net v0.17.0 // indirect
|
||||
golang.org/x/sys v0.13.0 // indirect
|
||||
golang.org/x/text v0.13.0 // indirect
|
||||
google.golang.org/appengine v1.6.8 // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
|
||||
google.golang.org/grpc v1.59.0 // indirect
|
||||
google.golang.org/protobuf v1.31.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.8 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
go 1.21
|
||||
go 1.22.4
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
cloud.google.com/go/compute/metadata v0.2.0 h1:nBbNSZyDpkNlo3DepaaLKVuO7ClyifSAmNloSCZrHnQ=
|
||||
cloud.google.com/go/compute/metadata v0.2.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k=
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go/compute v1.23.1 h1:V97tBoDaZHb6leicZ1G6DLK2BAaZLJ/7+9BB/En3hR0=
|
||||
cloud.google.com/go/compute v1.23.1/go.mod h1:CqB3xpmPKKt3OJpW2ndFIXnA9A4xAy/F3Xp1ixncW78=
|
||||
cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY=
|
||||
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
|
||||
github.com/99designs/httpsignatures-go v0.0.0-20170731043157-88528bf4ca7e/go.mod h1:Xa6lInWHNQnuWoF0YPSsx+INFA9qk7/7pTjwb3PInkY=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/aws/aws-sdk-go v1.26.7 h1:ObjEnmzvSdYy8KVd3me7v/UMyCn81inLy2SyoIPoBkg=
|
||||
github.com/aws/aws-sdk-go v1.26.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
@@ -18,14 +24,46 @@ github.com/drone-plugins/drone-plugin-lib v0.4.1 h1:47rZlmcMpr1hSp+6Gl+1Z4t+efi/
|
||||
github.com/drone-plugins/drone-plugin-lib v0.4.1/go.mod h1:KwCu92jFjHV3xv2hu5Qg/8zBNvGwbhoJDQw/EwnTvoM=
|
||||
github.com/drone/drone-go v1.7.1 h1:ZX+3Rs8YHUSUQ5mkuMLmm1zr1ttiiE2YGNxF3AnyDKw=
|
||||
github.com/drone/drone-go v1.7.1/go.mod h1:fxCf9jAnXDZV1yDr0ckTuWd1intvcQwfJmTRpTZ1mXg=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
|
||||
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
|
||||
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o=
|
||||
github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
|
||||
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.1 h1:SBWmZhjUDRorQxrN0nwzf+AHBxnbFjViHQS4P0yVpmQ=
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.3.1/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas=
|
||||
github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU=
|
||||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743 h1:X3Xxno5Ji8idrNiUoFc7QyXpqhSYlDRYQmc7mlpMBzU=
|
||||
github.com/inhies/go-bytesize v0.0.0-20210819104631-275770b98743/go.mod h1:KrtyD5PFj++GKkFS/7/RRrfnRhAMGQwy75GLCHWrCNs=
|
||||
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
|
||||
@@ -34,6 +72,7 @@ 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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
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/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
@@ -41,30 +80,112 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
|
||||
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
|
||||
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M=
|
||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
||||
golang.org/x/oauth2 v0.8.0 h1:6dkIjl3j3LtZ/O3sTgZTMsLKSftL/B8Zgq4huOIIUu8=
|
||||
golang.org/x/oauth2 v0.8.0/go.mod h1:yr7u4HXZRm1R1kBWqr/xKNqewf0plRYoB7sla+BCIXE=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
|
||||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
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-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
|
||||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
|
||||
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
|
||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
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-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
|
||||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
|
||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
|
||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/api v0.146.0 h1:9aBYT4vQXt9dhCuLNfwfd3zpwu8atg0yPkjBymwSrOM=
|
||||
google.golang.org/api v0.146.0/go.mod h1:OARJqIfoYjXJj4C1AiBSXYZt03qsoz8FQYU6fBEfrHM=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
|
||||
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
||||
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a h1:fwgW9j3vHirt4ObdHoYNwuO24BEZjSzbh+zPaNWoiY8=
|
||||
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:EMfReVxb80Dq1hhioy0sOsY9jCE46YDgHlJ7fWVUWRE=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb h1:lK0oleSc7IQsUxO3U5TjL9DWlsxpEBemh+zpB7IqhWI=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20230913181813-007df8e322eb/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk=
|
||||
google.golang.org/grpc v1.59.0/go.mod h1:aUPDwccQo6OTjy7Hct4AfBPD1GptF4fyUjIkQ9YtF98=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
|
||||
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
@@ -72,3 +193,5 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
v2HubRegistryURL string = "https://registry.hub.docker.com/v2/"
|
||||
v1RegistryURL string = "https://index.docker.io/v1/" // Default registry
|
||||
v2RegistryURL string = "https://index.docker.io/v2/" // v2 registry is not supported
|
||||
)
|
||||
|
||||
type (
|
||||
Auth struct {
|
||||
Auth string `json:"auth"`
|
||||
}
|
||||
|
||||
Config struct {
|
||||
Auths map[string]Auth `json:"auths"`
|
||||
CredHelpers map[string]string `json:"credHelpers,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
type RegistryCredentials struct {
|
||||
Registry string
|
||||
Username string
|
||||
Password string
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
Auths: make(map[string]Auth),
|
||||
CredHelpers: make(map[string]string),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) SetAuth(registry, username, password string) {
|
||||
authBytes := []byte(username + ":" + password)
|
||||
encodedString := base64.StdEncoding.EncodeToString(authBytes)
|
||||
c.Auths[registry] = Auth{Auth: encodedString}
|
||||
}
|
||||
|
||||
func (c *Config) SetCredHelper(registry, helper string) {
|
||||
c.CredHelpers[registry] = helper
|
||||
}
|
||||
|
||||
func (c *Config) CreateDockerConfigJson(credentials []RegistryCredentials) ([]byte, error) {
|
||||
for _, cred := range credentials {
|
||||
if cred.Registry != "" {
|
||||
|
||||
if cred.Username == "" {
|
||||
return nil, fmt.Errorf("Username must be specified for registry: %s", cred.Registry)
|
||||
}
|
||||
if cred.Password == "" {
|
||||
return nil, fmt.Errorf("Password must be specified for registry: %s", cred.Registry)
|
||||
}
|
||||
c.SetAuth(cred.Registry, cred.Username, cred.Password)
|
||||
}
|
||||
}
|
||||
|
||||
jsonBytes, err := json.Marshal(c)
|
||||
if err != nil {
|
||||
return nil, errors.New("failed to serialize docker config json")
|
||||
}
|
||||
|
||||
return jsonBytes, nil
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const (
|
||||
RegistryV1 string = "https://index.docker.io/v1/"
|
||||
RegistryV2 string = "https://index.docker.io/v2/"
|
||||
RegistryECRPublic string = "public.ecr.aws"
|
||||
)
|
||||
|
||||
func TestConfig(t *testing.T) {
|
||||
c := NewConfig()
|
||||
assert.NotNil(t, c.Auths)
|
||||
assert.NotNil(t, c.CredHelpers)
|
||||
|
||||
c.SetAuth(RegistryV1, "test", "password")
|
||||
expectedAuth := Auth{Auth: "dGVzdDpwYXNzd29yZA=="}
|
||||
assert.Equal(t, expectedAuth, c.Auths[RegistryV1])
|
||||
|
||||
c.SetCredHelper(RegistryECRPublic, "ecr-login")
|
||||
assert.Equal(t, "ecr-login", c.CredHelpers[RegistryECRPublic])
|
||||
|
||||
tempDir, err := ioutil.TempDir("", "docker-config-test")
|
||||
assert.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
|
||||
credentials := []RegistryCredentials{
|
||||
{
|
||||
Registry: "https://index.docker.io/v1/",
|
||||
Username: "user1",
|
||||
Password: "pass1",
|
||||
},
|
||||
{
|
||||
Registry: "gcr.io",
|
||||
Username: "user2",
|
||||
Password: "pass2",
|
||||
},
|
||||
}
|
||||
|
||||
jsonBytes, err := c.CreateDockerConfigJson(credentials)
|
||||
assert.NoError(t, err)
|
||||
|
||||
configPath := filepath.Join(tempDir, "config.json")
|
||||
err = ioutil.WriteFile(configPath, jsonBytes, 0644)
|
||||
assert.NoError(t, err)
|
||||
|
||||
data, err := ioutil.ReadFile(configPath)
|
||||
assert.NoError(t, err)
|
||||
|
||||
var configFromFile Config
|
||||
err = json.Unmarshal(data, &configFromFile)
|
||||
assert.NoError(t, err)
|
||||
|
||||
assert.Equal(t, c.Auths, configFromFile.Auths)
|
||||
assert.Equal(t, c.CredHelpers, configFromFile.CredHelpers)
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package gcp
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
"google.golang.org/api/iamcredentials/v1"
|
||||
"google.golang.org/api/option"
|
||||
"google.golang.org/api/sts/v1"
|
||||
)
|
||||
|
||||
type staticTokenSource struct {
|
||||
token *oauth2.Token
|
||||
}
|
||||
|
||||
func (s *staticTokenSource) Token() (*oauth2.Token, error) {
|
||||
return s.token, nil
|
||||
}
|
||||
|
||||
func GetFederalToken(idToken, projectNumber, poolId, providerId string) (string, error) {
|
||||
ctx := context.Background()
|
||||
stsService, err := sts.NewService(ctx, option.WithoutAuthentication())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
audience := fmt.Sprintf("//iam.googleapis.com/projects/%s/locations/global/workloadIdentityPools/%s/providers/%s", projectNumber, poolId, providerId)
|
||||
tokenRequest := &sts.GoogleIdentityStsV1ExchangeTokenRequest{
|
||||
GrantType: "urn:ietf:params:oauth:grant-type:token-exchange",
|
||||
SubjectToken: idToken,
|
||||
Audience: audience,
|
||||
Scope: "https://www.googleapis.com/auth/cloud-platform",
|
||||
RequestedTokenType: "urn:ietf:params:oauth:token-type:access_token",
|
||||
SubjectTokenType: "urn:ietf:params:oauth:token-type:id_token",
|
||||
}
|
||||
tokenResponse, err := stsService.V1.Token(tokenRequest).Do()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return tokenResponse.AccessToken, nil
|
||||
}
|
||||
|
||||
func GetGoogleCloudAccessToken(federatedToken string, serviceAccountEmail string) (string, error) {
|
||||
ctx := context.Background()
|
||||
tokenSource := &staticTokenSource{
|
||||
token: &oauth2.Token{AccessToken: federatedToken},
|
||||
}
|
||||
service, err := iamcredentials.NewService(ctx, option.WithTokenSource(tokenSource))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
name := "projects/-/serviceAccounts/" + serviceAccountEmail
|
||||
rb := &iamcredentials.GenerateAccessTokenRequest{
|
||||
Scope: []string{"https://www.googleapis.com/auth/cloud-platform"},
|
||||
}
|
||||
|
||||
resp, err := service.Projects.ServiceAccounts.GenerateAccessToken(name, rb).Do()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return resp.AccessToken, nil
|
||||
}
|
||||
Reference in New Issue
Block a user