68 Commits

Author SHA1 Message Date
Brad Rydzewski
e311310166 minor refactor to prep for cards 2022-01-12 11:18:55 -05:00
TP Honey
0ffe085ddc Merge pull request #351 from drone-plugins/win_fix
Fix windows docker builds
2022-01-10 10:02:17 +00:00
Shubham Agrawal
80d227e138 Fix windows docker builds 2022-01-08 00:31:45 +05:30
TP Honey
64b6aa187d Merge pull request #350 from drone-plugins/fix_win_pipeline
Fix powershell script to publish windows images
2022-01-07 10:27:13 +00:00
Shubham Agrawal
74ec8ac761 Fix powershell script to publish windows images 2022-01-07 11:41:11 +05:30
TP Honey
368583a464 Merge pull request #348 from drone-plugins/serialize_win_1809
Serialize windows 1809 pipelines
2022-01-06 14:03:37 +00:00
Shubham Agrawal
28175f4003 Serialize windows 1809 pipelines 2022-01-06 13:28:00 +05:30
Shubham Agrawal
85e715fd5d Support for windows images for tags (#346) 2022-01-05 23:28:27 +05:30
Eoin McAfee
4d8c628184 Merge pull request #342 from drone-plugins/task/bump-latest-version
bump to version 20.10.9:
2021-11-03 08:47:17 +00:00
Eoin McAfee
0244fdbc12 bump to version 20.10.9: 2021-11-02 11:23:08 +00:00
Eoin McAfee
28105d09d1 Merge pull request #334 from gzm0/upgrade-dind
Upgrade Docker dind to 20.10.9 for 64bit platforms
2021-11-02 11:03:25 +00:00
Tobias Schlatter
501eae03f2 Upgrade to dind 20.10.9 which has been released in the meanwhile 2021-10-18 16:45:12 +02:00
Tobias Schlatter
5490a1c24c Upgrade Docker dind to 20.10.8 for 64bit platforms
This is an alternative to #327. As the discussion on that PR shows, it
seems docker is not going to provide updates for the arm32 platform
anymore.

Fixes #326 and fixes #330.
2021-10-18 16:45:12 +02:00
TP Honey
6ec5e71411 Merge pull request #338 from tphoney/bump-go-1.13
(maint) bump git to 1.13 for build and test
2021-10-13 17:19:30 +01:00
TP Honey
0911e6a922 (maint) bump git to 1.13 for build and test 2021-10-13 14:53:32 +01:00
TP Honey
88f8bf1cb0 Merge pull request #337 from tphoney/prep_v19.03.9
(maint) v19.03.9 release prep
2021-10-13 14:32:03 +01:00
TP Honey
2d70a1fa7c (maint) v19.03.9 release prep 2021-10-13 14:27:33 +01:00
Eoin McAfee
607b04a871 Merge pull request #333 from jimsheldon/ecr-externalid
adding support for externalId
2021-09-23 15:52:24 +01:00
Jim Sheldon
e44c2d46ea adding support for externalId 2021-09-17 15:33:05 -04:00
Brad Rydzewski
72ef7b1f3f log available credentials before login 2021-08-02 22:15:39 -04:00
Brad Rydzewski
fbbeec5a2e use Replace instead of ReplaceAll 2021-08-02 21:42:22 -04:00
Brad Rydzewski
b1d8698d1c print login failure reason to output 2021-08-02 21:28:37 -04:00
Brad Rydzewski
d4cf9f20f1 remove pull always 2021-07-11 15:50:43 -04:00
Brad Rydzewski
f75380013d Merge pull request #325 from drone-plugins/revert-322-update-seccomp
Revert "Update seccomp to 20.10 docker"
2021-07-11 15:39:35 -04:00
Brad Rydzewski
c10d36754c Revert "Update seccomp to 20.10 docker (#322)"
This reverts commit dd359dfc72.
2021-07-11 15:38:04 -04:00
techknowlogick
dd359dfc72 Update seccomp to 20.10 docker (#322)
* Update seccomp to 20.10 docker
2021-07-07 20:03:54 +01:00
TP Honey
729aa5d300 Merge pull request #323 from tphoney/docker_rate_limit
(maint) CI, remove the dry run steps, due to rate limiting
2021-07-07 19:52:19 +01:00
TP Honey
db5c2161fe (maint) CI, remove the dry run steps, due to rate limiting 2021-07-07 19:37:30 +01:00
Brad Rydzewski
f08821b024 Merge pull request #300 from rvoitenko/ecr_scan_on_push
ECR: adding setting to enable image scanning while repo creation
2021-04-06 15:55:56 -04:00
Brad Rydzewski
0f6bd8a62e Merge pull request #313 from codrut-fc/opencontainer-labels
Add support for automatic opencontainer labels
2021-03-01 20:52:08 -05:00
Roman Voitenko
5760e7b4e8 Merge branch 'master' into ecr_scan_on_push 2021-02-20 13:32:16 +01:00
Brad Rydzewski
7ade37a140 Update .drone.yml 2021-02-16 09:44:28 -05:00
Brad Rydzewski
319660d758 Merge pull request #312 from xoxys/master
add custom seccomp profile
2021-02-09 16:29:27 -05:00
Codruț Constantin Gușoi
bd4029884c Add support for automatic opencontainer labels 2021-01-20 18:14:27 +00:00
Robert Kaussow
b1959299c7 load the patched seccomp profile only on arm 2021-01-17 18:40:36 +01:00
Robert Kaussow
bfdf3034c1 add custom seccomp profile 2021-01-17 14:27:49 +01:00
Brad Rydzewski
9c86f98ea5 Update main.go 2020-11-25 11:51:03 -05:00
Brad Rydzewski
faec3cf9d8 temporarily revert to last working yaml [CI SKIP] 2020-11-19 17:12:28 -05:00
Don
ad1fa9495f Merge pull request #303 from drone-plugins/fix-windows-build
Fix Windows build
2020-11-09 16:44:15 -08:00
Don
799cc8e35e Fix Windows build
The Windows docker builds should only be triggered when there's a push to master or
a tag. Also add proper tagging to the Windows builds.
2020-10-16 07:26:12 -07:00
Brad Rydzewski
5834d8dff9 Merge pull request #304 from tonglil/typos [CI SKIP]
minor typo
2020-10-16 10:10:19 -04:00
Tony Li
4abe7c9d20 minor typo 2020-10-15 15:41:26 -07:00
Roman Voitenko
3501d9a65d add possibility to turn on/off image scanning not only during repo creation, but when repo already created 2020-10-01 10:43:25 +02:00
Roman Voitenko
d8b6b48fa3 add possibility to turn on ECR image scanning for repos created by ecr plugin 2020-09-30 23:32:23 +02:00
Brad Rydzewski
e4056d8499 Merge pull request #296 from robertstettner/added-godotenv-for-non-base
Added env-file with godotenv to all non-base implementations of plugin
2020-08-11 11:24:23 -04:00
Robert Stettner
a5076e74dc Added env-file with godotenv to all non-base implementations of plugin 2020-08-05 16:28:21 +01:00
Brad Rydzewski
d913d6e7dc Merge pull request #279 from drone-plugins/feature/semver-fail
semver parsing fails pipeline step
2020-06-08 14:57:13 -04:00
Brad Rydzewski
1482cb1143 Merge pull request #285 from luthermonson/prune-loc
changed prune to 3rd arg in check
2020-05-28 12:06:46 -07:00
Luther
eb6d634460 changed prune to 3rd arg in check 2020-05-28 11:48:36 -07:00
Brad Rydzewski
77396e3f59 Clarify use of Docker-in-Docker [CI SKIP] 2020-05-28 13:22:31 -04:00
Brad Rydzewski
675553c96d Merge pull request #262 from tuxity/docker_update
Update Docker to 19.03.8
2020-05-28 10:20:37 -07:00
Brad Rydzewski
d929356ba1 Merge pull request #281 from luthermonson/no-error-cleanup
Adding Ignore Checks for prune and rmi
2020-05-22 13:48:44 -07:00
Luther
9701f08184 adding ignore checks for prune and rmi 2020-05-22 13:15:19 -07:00
Brad Rydzewski
6cc2e43e64 semver parsing fails pipeline step 2020-05-19 13:26:13 -04:00
Thomas Boerger
b5598ee56d Merge pull request #274 from gary-kim/enh/noid/quiet-option
Add quiet build option
2020-05-18 09:41:22 +02:00
Thomas Boerger
8219e78eca Merge branch 'master' into enh/noid/quiet-option 2020-05-18 09:36:48 +02:00
Kévin Darcel
23b5e6bcd9 Update linux Dockerfile to 19.03.8 2020-05-05 15:31:17 -05:00
Kévin Darcel
56e470dcda Start daemon with Unix socket only
Mostly reproduce flow of https://github.com/docker-library/docker/blob/master/19.03/dind/dockerd-entrypoint.sh#L130
TCP socket with or without TLS isn't really needed for our usecase so
it's disable
2020-05-02 17:09:35 -05:00
Kévin Darcel
8d54531f2f Update to docker 19.03.05 2020-05-02 17:09:35 -05:00
Brad Rydzewski
05c329ab6e Merge pull request #266 from luthermonson/win-1909
adding windows 1909
2020-05-02 08:58:40 -07:00
Gary Kim
0099cd6056 Add quiet build option
This adds the option for using the `--quiet` flag during builds.

Signed-off-by: Gary Kim <gary@garykim.dev>
2020-04-29 14:11:31 +08:00
Thomas Boerger
00ee2c290c Merge pull request #259 from aviettran/master
Update AWS SDK
2020-04-16 09:29:39 +02:00
Thomas Boerger
65bb87f497 Merge branch 'master' into master 2020-04-16 09:24:34 +02:00
Luther Monson
bae9d8ddbf adding windows 1909 2020-03-12 10:46:57 -07:00
Adam Tran
af9fdad1d9 update urfave/cli to 1.22.2 2020-01-02 16:32:11 -05:00
Adam Tran
196c393da4 update sum 2020-01-02 11:41:54 -05:00
Adam Tran
c69ad3dfaf remove urfave/cli 2020-01-02 11:40:30 -05:00
Adam Tran
c6dab33e03 Update AWS SDK 2020-01-02 09:42:44 -05:00
38 changed files with 994 additions and 536 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,2 @@
since-tag=v19.03.8

35
CHANGELOG.md Normal file
View File

@@ -0,0 +1,35 @@
# Changelog
## [v20.10.9](https://github.com/drone-plugins/drone-docker/tree/v20.10.9) (2021-11-02)
[Full Changelog](https://github.com/drone-plugins/drone-docker/compare/v19.03.9...v20.10.9)
**Merged pull requests:**
- Upgrade Docker dind to 20.10.9 for 64bit platforms [\#334](https://github.com/drone-plugins/drone-docker/pull/334) ([gzm0](https://github.com/gzm0))
## [v19.03.9](https://github.com/drone-plugins/drone-docker/tree/v19.03.9) (2021-10-13)
[Full Changelog](https://github.com/drone-plugins/drone-docker/compare/v19.03.8...v19.03.9)
**Implemented enhancements:**
- adding support for externalId [\#333](https://github.com/drone-plugins/drone-docker/pull/333) ([jimsheldon](https://github.com/jimsheldon))
- Add support for automatic opencontainer labels [\#313](https://github.com/drone-plugins/drone-docker/pull/313) ([codrut-fc](https://github.com/codrut-fc))
- add custom seccomp profile [\#312](https://github.com/drone-plugins/drone-docker/pull/312) ([xoxys](https://github.com/xoxys))
- ECR: adding setting to enable image scanning while repo creation [\#300](https://github.com/drone-plugins/drone-docker/pull/300) ([rvoitenko](https://github.com/rvoitenko))
**Fixed bugs:**
- Revert "Update seccomp to 20.10 docker" [\#325](https://github.com/drone-plugins/drone-docker/pull/325) ([bradrydzewski](https://github.com/bradrydzewski))
**Merged pull requests:**
- \(maint\) bump git to 1.13 for build and test [\#338](https://github.com/drone-plugins/drone-docker/pull/338) ([tphoney](https://github.com/tphoney))
- \(maint\) v19.03.9 release prep [\#337](https://github.com/drone-plugins/drone-docker/pull/337) ([tphoney](https://github.com/tphoney))
- \(maint\) CI, remove the dry run steps, due to rate limiting [\#323](https://github.com/drone-plugins/drone-docker/pull/323) ([tphoney](https://github.com/tphoney))
- Update seccomp to 20.10 docker [\#322](https://github.com/drone-plugins/drone-docker/pull/322) ([techknowlogick](https://github.com/techknowlogick))
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*

View File

@@ -8,7 +8,7 @@
[![Go Doc](https://godoc.org/github.com/drone-plugins/drone-docker?status.svg)](http://godoc.org/github.com/drone-plugins/drone-docker) [![Go Doc](https://godoc.org/github.com/drone-plugins/drone-docker?status.svg)](http://godoc.org/github.com/drone-plugins/drone-docker)
[![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-docker)](https://goreportcard.com/report/github.com/drone-plugins/drone-docker) [![Go Report](https://goreportcard.com/badge/github.com/drone-plugins/drone-docker)](https://goreportcard.com/report/github.com/drone-plugins/drone-docker)
Drone plugin 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/). 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/).
## Build ## Build
@@ -72,3 +72,23 @@ docker run --rm \
--privileged \ --privileged \
plugins/docker --dry-run plugins/docker --dry-run
``` ```
## Release procedure
Run the changelog generator.
```BASH
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-docker -t <secret github token>
```
You can generate a token by logging into your GitHub account and going to Settings -> Personal access tokens.
Next we tag the PR's with the fixes or enhancements labels. If the PR does not fufil the requirements, do not add a label.
Run the changelog generator again with the future version according to semver.
```BASH
docker run -it --rm -v "$(pwd)":/usr/local/src/your-app githubchangeloggenerator/github-changelog-generator -u drone-plugins -p drone-docker -t <secret token> --future-release v1.0.0
```
Create your pull request for the release. Get it merged then tag the release.

48
card.go Normal file
View File

@@ -0,0 +1,48 @@
package docker
import (
"encoding/base64"
"encoding/json"
"io"
"io/ioutil"
"os"
"os/exec"
)
func (p Plugin) writeCard() error {
cmd := exec.Command("docker", "inspect", p.Build.Name)
data, err := cmd.CombinedOutput()
if err != nil {
return err
}
out := map[string]interface{}{} // replace with docker inspect struct
if err := json.Unmarshal(data, &out); err != nil {
return err
}
card := map[string]interface{}{} // replace with card struct, populate with docker inspect output
writeCard( /*p.CardPath*/ "", &card)
return nil
}
func writeCard(path string, card interface{}) {
data, _ := json.Marshal(card)
switch {
case path == "/dev/stdout":
writeCardTo(os.Stdout, data)
case path == "/dev/stderr":
writeCardTo(os.Stderr, data)
case path != "":
ioutil.WriteFile(path, data, 0644)
}
}
func writeCardTo(out io.Writer, data []byte) {
encoded := base64.StdEncoding.EncodeToString(data)
io.WriteString(out, "\u001B]1338;")
io.WriteString(out, encoded)
io.WriteString(out, "\u001B]0m")
io.WriteString(out, "\n")
}

View File

@@ -5,9 +5,16 @@ import (
"os" "os"
"os/exec" "os/exec"
"strings" "strings"
"github.com/joho/godotenv"
) )
func main() { func main() {
// Load env-file if it exists first
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
godotenv.Load(env)
}
var ( var (
repo = getenv("PLUGIN_REPO") repo = getenv("PLUGIN_REPO")
registry = getenv("PLUGIN_REGISTRY") registry = getenv("PLUGIN_REGISTRY")

View File

@@ -50,7 +50,7 @@ func main() {
cli.StringFlag{ cli.StringFlag{
Name: "daemon.mirror", Name: "daemon.mirror",
Usage: "docker daemon registry mirror", Usage: "docker daemon registry mirror",
EnvVar: "PLUGIN_MIRROR", EnvVar: "PLUGIN_MIRROR,DOCKER_PLUGIN_MIRROR",
}, },
cli.StringFlag{ cli.StringFlag{
Name: "daemon.storage-driver", Name: "daemon.storage-driver",
@@ -147,6 +147,11 @@ func main() {
Usage: "build args", Usage: "build args",
EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV", EnvVar: "PLUGIN_BUILD_ARGS_FROM_ENV",
}, },
cli.BoolFlag{
Name: "quiet",
Usage: "quiet docker build",
EnvVar: "PLUGIN_QUIET",
},
cli.StringFlag{ cli.StringFlag{
Name: "target", Name: "target",
Usage: "build target", Usage: "build target",
@@ -187,6 +192,16 @@ func main() {
Usage: "label-schema labels", Usage: "label-schema labels",
EnvVar: "PLUGIN_LABEL_SCHEMA", EnvVar: "PLUGIN_LABEL_SCHEMA",
}, },
cli.BoolTFlag{
Name: "auto-label",
Usage: "auto-label true|false",
EnvVar: "PLUGIN_AUTO_LABEL",
},
cli.StringFlag{
Name: "link",
Usage: "link https://example.com/org/repo-name",
EnvVar: "PLUGIN_REPO_LINK,DRONE_REPO_LINK",
},
cli.StringFlag{ cli.StringFlag{
Name: "docker.registry", Name: "docker.registry",
Usage: "docker registry", Usage: "docker registry",
@@ -211,7 +226,7 @@ func main() {
cli.StringFlag{ cli.StringFlag{
Name: "docker.config", Name: "docker.config",
Usage: "docker json dockerconfig content", Usage: "docker json dockerconfig content",
EnvVar: "PLUGIN_CONFIG", EnvVar: "PLUGIN_CONFIG,DOCKER_PLUGIN_CONFIG",
}, },
cli.BoolTFlag{ cli.BoolTFlag{
Name: "docker.purge", Name: "docker.purge",
@@ -252,23 +267,26 @@ func run(c *cli.Context) error {
Config: c.String("docker.config"), Config: c.String("docker.config"),
}, },
Build: docker.Build{ Build: docker.Build{
Remote: c.String("remote.url"), Remote: c.String("remote.url"),
Name: c.String("commit.sha"), Name: c.String("commit.sha"),
Dockerfile: c.String("dockerfile"), Dockerfile: c.String("dockerfile"),
Context: c.String("context"), Context: c.String("context"),
Tags: c.StringSlice("tags"), Tags: c.StringSlice("tags"),
Args: c.StringSlice("args"), Args: c.StringSlice("args"),
ArgsEnv: c.StringSlice("args-from-env"), ArgsEnv: c.StringSlice("args-from-env"),
Target: c.String("target"), Target: c.String("target"),
Squash: c.Bool("squash"), Squash: c.Bool("squash"),
Pull: c.BoolT("pull-image"), Pull: c.BoolT("pull-image"),
CacheFrom: c.StringSlice("cache-from"), CacheFrom: c.StringSlice("cache-from"),
Compress: c.Bool("compress"), Compress: c.Bool("compress"),
Repo: c.String("repo"), Repo: c.String("repo"),
Labels: c.StringSlice("custom-labels"), Labels: c.StringSlice("custom-labels"),
LabelSchema: c.StringSlice("label-schema"), LabelSchema: c.StringSlice("label-schema"),
NoCache: c.Bool("no-cache"), AutoLabel: c.BoolT("auto-label"),
AddHost: c.StringSlice("add-host"), Link: c.String("link"),
NoCache: c.Bool("no-cache"),
AddHost: c.StringSlice("add-host"),
Quiet: c.Bool("quiet"),
}, },
Daemon: docker.Daemon{ Daemon: docker.Daemon{
Registry: c.String("docker.registry"), Registry: c.String("docker.registry"),
@@ -292,10 +310,15 @@ func run(c *cli.Context) error {
c.String("commit.ref"), c.String("commit.ref"),
c.String("repo.branch"), c.String("repo.branch"),
) { ) {
plugin.Build.Tags = docker.DefaultTagSuffix( tag, err := docker.DefaultTagSuffix(
c.String("commit.ref"), c.String("commit.ref"),
c.String("tags.suffix"), c.String("tags.suffix"),
) )
if err != nil {
logrus.Printf("cannot build docker image for %s, invalid semantic version", c.String("commit.ref"))
return err
}
plugin.Build.Tags = tag
} else { } else {
logrus.Printf("skipping automated docker build for %s", c.String("commit.ref")) logrus.Printf("skipping automated docker build for %s", c.String("commit.ref"))
return nil return nil

View File

@@ -10,6 +10,8 @@ import (
"strconv" "strconv"
"strings" "strings"
"github.com/joho/godotenv"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" "github.com/aws/aws-sdk-go/aws/credentials/stscreds"
@@ -20,6 +22,11 @@ import (
const defaultRegion = "us-east-1" const defaultRegion = "us-east-1"
func main() { func main() {
// Load env-file if it exists first
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
godotenv.Load(env)
}
var ( var (
repo = getenv("PLUGIN_REPO") repo = getenv("PLUGIN_REPO")
registry = getenv("PLUGIN_REGISTRY") registry = getenv("PLUGIN_REGISTRY")
@@ -30,6 +37,8 @@ func main() {
lifecyclePolicy = getenv("PLUGIN_LIFECYCLE_POLICY") lifecyclePolicy = getenv("PLUGIN_LIFECYCLE_POLICY")
repositoryPolicy = getenv("PLUGIN_REPOSITORY_POLICY") repositoryPolicy = getenv("PLUGIN_REPOSITORY_POLICY")
assumeRole = getenv("PLUGIN_ASSUME_ROLE") assumeRole = getenv("PLUGIN_ASSUME_ROLE")
externalId = getenv("PLUGIN_EXTERNAL_ID")
scanOnPush = parseBoolOrDefault(false, getenv("PLUGIN_SCAN_ON_PUSH"))
) )
// set the region // set the region
@@ -49,7 +58,7 @@ func main() {
log.Fatal(fmt.Sprintf("error creating aws session: %v", err)) log.Fatal(fmt.Sprintf("error creating aws session: %v", err))
} }
svc := getECRClient(sess, assumeRole) svc := getECRClient(sess, assumeRole, externalId)
username, password, defaultRegistry, err := getAuthInfo(svc) username, password, defaultRegistry, err := getAuthInfo(svc)
if registry == "" { if registry == "" {
@@ -65,10 +74,14 @@ func main() {
} }
if create { if create {
err = ensureRepoExists(svc, trimHostname(repo, registry)) err = ensureRepoExists(svc, trimHostname(repo, registry), scanOnPush)
if err != nil { if err != nil {
log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err)) log.Fatal(fmt.Sprintf("error creating ECR repo: %v", err))
} }
err = updateImageScannningConfig(svc, trimHostname(repo, registry), scanOnPush)
if err != nil {
log.Fatal(fmt.Sprintf("error updating scan on push for ECR repo: %v", err))
}
} }
if lifecyclePolicy != "" { if lifecyclePolicy != "" {
@@ -111,9 +124,10 @@ func trimHostname(repo, registry string) string {
return repo return repo
} }
func ensureRepoExists(svc *ecr.ECR, name string) (err error) { func ensureRepoExists(svc *ecr.ECR, name string, scanOnPush bool) (err error) {
input := &ecr.CreateRepositoryInput{} input := &ecr.CreateRepositoryInput{}
input.SetRepositoryName(name) input.SetRepositoryName(name)
input.SetImageScanningConfiguration(&ecr.ImageScanningConfiguration{ScanOnPush: &scanOnPush})
_, err = svc.CreateRepository(input) _, err = svc.CreateRepository(input)
if err != nil { if err != nil {
if aerr, ok := err.(awserr.Error); ok && aerr.Code() == ecr.ErrCodeRepositoryAlreadyExistsException { if aerr, ok := err.(awserr.Error); ok && aerr.Code() == ecr.ErrCodeRepositoryAlreadyExistsException {
@@ -125,6 +139,15 @@ func ensureRepoExists(svc *ecr.ECR, name string) (err error) {
return return
} }
func updateImageScannningConfig(svc *ecr.ECR, name string, scanOnPush bool) (err error) {
input := &ecr.PutImageScanningConfigurationInput{}
input.SetRepositoryName(name)
input.SetImageScanningConfiguration(&ecr.ImageScanningConfiguration{ScanOnPush: &scanOnPush})
_, err = svc.PutImageScanningConfiguration(input)
return err
}
func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (err error) { func uploadLifeCyclePolicy(svc *ecr.ECR, lifecyclePolicy string, name string) (err error) {
input := &ecr.PutLifecyclePolicyInput{} input := &ecr.PutLifecyclePolicyInput{}
input.SetLifecyclePolicyText(lifecyclePolicy) input.SetLifecyclePolicyText(lifecyclePolicy)
@@ -186,11 +209,19 @@ func getenv(key ...string) (s string) {
return return
} }
func getECRClient(sess *session.Session, role string) *ecr.ECR { func getECRClient(sess *session.Session, role string, externalId string) *ecr.ECR {
if role == "" { if role == "" {
return ecr.New(sess) return ecr.New(sess)
} }
return ecr.New(sess, &aws.Config{ if externalId != "" {
Credentials: stscreds.NewCredentials(sess, role), return ecr.New(sess, &aws.Config{
}) Credentials: stscreds.NewCredentials(sess, role, func(p *stscreds.AssumeRoleProvider) {
p.ExternalID = &externalId
}),
})
} else {
return ecr.New(sess, &aws.Config{
Credentials: stscreds.NewCredentials(sess, role),
})
}
} }

View File

@@ -6,12 +6,19 @@ import (
"os/exec" "os/exec"
"path" "path"
"strings" "strings"
"github.com/joho/godotenv"
) )
// gcr default username // gcr default username
const username = "_json_key" const username = "_json_key"
func main() { func main() {
// Load env-file if it exists first
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
godotenv.Load(env)
}
var ( var (
repo = getenv("PLUGIN_REPO") repo = getenv("PLUGIN_REPO")
registry = getenv("PLUGIN_REGISTRY") registry = getenv("PLUGIN_REGISTRY")

View File

@@ -4,9 +4,16 @@ import (
"os" "os"
"os/exec" "os/exec"
"path" "path"
"github.com/joho/godotenv"
) )
func main() { func main() {
// Load env-file if it exists first
if env := os.Getenv("PLUGIN_ENV_FILE"); env != "" {
godotenv.Load(env)
}
var ( var (
registry = "registry.heroku.com" registry = "registry.heroku.com"
process = getenv("PLUGIN_PROCESS_TYPE") process = getenv("PLUGIN_PROCESS_TYPE")

132
docker.go
View File

@@ -53,9 +53,12 @@ type (
Compress bool // Docker build compress Compress bool // Docker build compress
Repo string // Docker build repository Repo string // Docker build repository
LabelSchema []string // label-schema Label map LabelSchema []string // label-schema Label map
AutoLabel bool // auto-label bool
Labels []string // Label map Labels []string // Label map
Link string // Git repo link
NoCache bool // Docker build no-cache NoCache bool // Docker build no-cache
AddHost []string // Docker build add-host AddHost []string // Docker build add-host
Quiet bool // Docker build quiet
} }
// Plugin defines the Docker plugin parameters. // Plugin defines the Docker plugin parameters.
@@ -77,36 +80,24 @@ func (p Plugin) Exec() error {
// poll the docker daemon until it is started. This ensures the daemon is // poll the docker daemon until it is started. This ensures the daemon is
// ready to accept connections before we proceed. // ready to accept connections before we proceed.
for i := 0; i < 15; i++ { for i := 0; ; i++ {
cmd := commandInfo() cmd := commandInfo()
err := cmd.Run() err := cmd.Run()
if err == nil { if err == nil {
break break
} }
if i == 15 {
fmt.Println("Unable to reach Docker Daemon after 15 attempts.")
break
}
time.Sleep(time.Second * 1) time.Sleep(time.Second * 1)
} }
// Create Auth Config File // for debugging purposes, log the type of authentication
if p.Login.Config != "" { // credentials that have been provided.
os.MkdirAll(dockerHome, 0600)
path := filepath.Join(dockerHome, "config.json")
err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writeing config.json: %s", err)
}
}
// login to the Docker registry
if p.Login.Password != "" {
cmd := commandLogin(p.Login)
err := cmd.Run()
if err != nil {
return fmt.Errorf("Error authenticating: %s", err)
}
}
switch { switch {
case p.Login.Password != "" && p.Login.Config != "":
fmt.Println("Detected registry credentials and registry credentials file")
case p.Login.Password != "": case p.Login.Password != "":
fmt.Println("Detected registry credentials") fmt.Println("Detected registry credentials")
case p.Login.Config != "": case p.Login.Config != "":
@@ -115,6 +106,29 @@ func (p Plugin) Exec() error {
fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.") fmt.Println("Registry credentials or Docker config not provided. Guest mode enabled.")
} }
// create Auth Config File
if p.Login.Config != "" {
os.MkdirAll(dockerHome, 0600)
path := filepath.Join(dockerHome, "config.json")
err := ioutil.WriteFile(path, []byte(p.Login.Config), 0600)
if err != nil {
return fmt.Errorf("Error writing config.json: %s", err)
}
}
// login to the Docker registry
if p.Login.Password != "" {
cmd := commandLogin(p.Login)
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: exit status 1")
}
}
if p.Build.Squash && !p.Daemon.Experimental { if p.Build.Squash && !p.Daemon.Experimental {
fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...") fmt.Println("Squash build flag is only available when Docker deamon is started with experimental flag. Ignoring...")
p.Build.Squash = false p.Build.Squash = false
@@ -142,11 +156,6 @@ func (p Plugin) Exec() error {
} }
} }
if p.Cleanup {
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
cmds = append(cmds, commandPrune()) // docker system prune -f
}
// execute all commands in batch mode. // execute all commands in batch mode.
for _, cmd := range cmds { for _, cmd := range cmds {
cmd.Stdout = os.Stdout cmd.Stdout = os.Stdout
@@ -156,11 +165,35 @@ func (p Plugin) Exec() error {
err := cmd.Run() err := cmd.Run()
if err != nil && isCommandPull(cmd.Args) { if err != nil && isCommandPull(cmd.Args) {
fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2]) fmt.Printf("Could not pull cache-from image %s. Ignoring...\n", cmd.Args[2])
} else if err != nil && isCommandPrune(cmd.Args) {
fmt.Printf("Could not prune system containers. Ignoring...\n")
} else if err != nil && isCommandRmi(cmd.Args) {
fmt.Printf("Could not remove image %s. Ignoring...\n", cmd.Args[2])
} else if err != nil { } else if err != nil {
return err return err
} }
} }
// output the adaptive card
if err := p.writeCard(); err != nil {
fmt.Printf("Could not create adaptive card. %s\n", err)
}
// execute cleanup routines in batch mode
if p.Cleanup {
// clear the slice
cmds = nil
cmds = append(cmds, commandRmi(p.Build.Name)) // docker rmi
cmds = append(cmds, commandPrune()) // docker system prune -f
for _, cmd := range cmds {
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
trace(cmd)
}
}
return nil return nil
} }
@@ -243,20 +276,26 @@ func commandBuild(build Build) *exec.Cmd {
if build.Target != "" { if build.Target != "" {
args = append(args, "--target", build.Target) args = append(args, "--target", build.Target)
} }
if build.Quiet {
labelSchema := []string{ args = append(args, "--quiet")
"schema-version=1.0",
fmt.Sprintf("build-date=%s", time.Now().Format(time.RFC3339)),
fmt.Sprintf("vcs-ref=%s", build.Name),
fmt.Sprintf("vcs-url=%s", build.Remote),
} }
if len(build.LabelSchema) > 0 { if build.AutoLabel {
labelSchema = append(labelSchema, build.LabelSchema...) labelSchema := []string{
} fmt.Sprintf("created=%s", time.Now().Format(time.RFC3339)),
fmt.Sprintf("revision=%s", build.Name),
fmt.Sprintf("source=%s", build.Remote),
fmt.Sprintf("url=%s", build.Link),
}
labelPrefix := "org.opencontainers.image"
for _, label := range labelSchema { if len(build.LabelSchema) > 0 {
args = append(args, "--label", fmt.Sprintf("org.label-schema.%s", label)) labelSchema = append(labelSchema, build.LabelSchema...)
}
for _, label := range labelSchema {
args = append(args, "--label", fmt.Sprintf("%s.%s", labelPrefix, label))
}
} }
if len(build.Labels) > 0 { if len(build.Labels) > 0 {
@@ -330,7 +369,14 @@ func commandPush(build Build, tag string) *exec.Cmd {
// helper function to create the docker daemon command. // helper function to create the docker daemon command.
func commandDaemon(daemon Daemon) *exec.Cmd { func commandDaemon(daemon Daemon) *exec.Cmd {
args := []string{"--data-root", daemon.StoragePath} args := []string{
"--data-root", daemon.StoragePath,
"--host=unix:///var/run/docker.sock",
}
if _, err := os.Stat("/etc/docker/default.json"); err == nil {
args = append(args, "--seccomp-profile=/etc/docker/default.json")
}
if daemon.StorageDriver != "" { if daemon.StorageDriver != "" {
args = append(args, "-s", daemon.StorageDriver) args = append(args, "-s", daemon.StorageDriver)
@@ -362,10 +408,20 @@ func commandDaemon(daemon Daemon) *exec.Cmd {
return exec.Command(dockerdExe, args...) return exec.Command(dockerdExe, args...)
} }
// helper to check if args match "docker prune"
func isCommandPrune(args []string) bool {
return len(args) > 3 && args[2] == "prune"
}
func commandPrune() *exec.Cmd { func commandPrune() *exec.Cmd {
return exec.Command(dockerExe, "system", "prune", "-f") return exec.Command(dockerExe, "system", "prune", "-f")
} }
// helper to check if args match "docker rmi"
func isCommandRmi(args []string) bool {
return len(args) > 2 && args[1] == "rmi"
}
func commandRmi(tag string) *exec.Cmd { func commandRmi(tag string) *exec.Cmd {
return exec.Command(dockerExe, "rmi", tag) return exec.Command(dockerExe, "rmi", tag)
} }

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1803 FROM plugins/docker:windows-1803-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ACR" ` org.label-schema.name="Drone ACR" `

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1809 FROM plugins/docker:windows-1809-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ACR" ` org.label-schema.name="Drone ACR" `

View File

@@ -0,0 +1,10 @@
# escape=`
FROM plugins/docker:windows-1909-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ACR" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-acr.exe C:/bin/drone-acr.exe
ENTRYPOINT [ "C:\\bin\\drone-acr.exe" ]

View File

@@ -24,14 +24,26 @@ manifests:
os: linux os: linux
variant: v7 variant: v7
- -
image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803 image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1803 version: 1803
- -
image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1809 version: 1809
-
image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64
platform:
architecture: amd64
os: windows
version: 1903
-
image: plugins/acr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
platform:
architecture: amd64
os: windows
version: 1909

View File

@@ -1,4 +1,6 @@
FROM docker:18.09.0-dind FROM docker:20.10.9-dind
ENV DOCKER_HOST=unix:///var/run/docker.sock
ADD release/linux/amd64/drone-docker /bin/ ADD release/linux/amd64/drone-docker /bin/
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"]

View File

@@ -1,4 +1,15 @@
FROM arm32v6/docker:18.09.0-dind FROM arm32v6/docker:19.03.8-dind
ENV DOCKER_HOST=unix:///var/run/docker.sock
RUN apk --update add --virtual .build-deps curl && \
mkdir -p /etc/docker/ && \
curl -SsL -o /etc/docker/default.json https://raw.githubusercontent.com/moby/moby/19.03/profiles/seccomp/default.json && \
sed -i 's/SCMP_ACT_ERRNO/SCMP_ACT_TRACE/g' /etc/docker/default.json && \
chmod 600 /etc/docker/default.json && \
apk del .build-deps && \
rm -rf /var/cache/apk/* && \
rm -rf /tmp/*
ADD release/linux/arm/drone-docker /bin/ ADD release/linux/arm/drone-docker /bin/
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"]

View File

@@ -1,4 +1,6 @@
FROM arm64v8/docker:18.09.0-dind FROM arm64v8/docker:20.10.9-dind
ENV DOCKER_HOST=unix:///var/run/docker.sock
ADD release/linux/arm64/drone-docker /bin/ ADD release/linux/arm64/drone-docker /bin/
ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"] ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh", "/bin/drone-docker"]

View File

@@ -0,0 +1,28 @@
# escape=`
FROM mcr.microsoft.com/windows/servercore:1909 as download
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENV DOCKER_VERSION 19.03.1
RUN Invoke-WebRequest 'http://constexpr.org/innoextract/files/innoextract-1.7-windows.zip' -OutFile 'innoextract.zip' -UseBasicParsing ; `
Expand-Archive innoextract.zip -DestinationPath C:\ ; `
Remove-Item -Path innoextract.zip
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ; `
Invoke-WebRequest $('https://github.com/docker/toolbox/releases/download/v{0}/DockerToolbox-{0}.exe' -f $env:DOCKER_VERSION) -OutFile 'dockertoolbox.exe' -UseBasicParsing
RUN /innoextract.exe dockertoolbox.exe
FROM mcr.microsoft.com/windows/nanoserver:1909
USER ContainerAdministrator
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone Docker" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
RUN mkdir C:\bin
COPY --from=download /windows/system32/netapi32.dll /windows/system32/netapi32.dll
COPY --from=download /app/docker.exe C:/bin/docker.exe
ADD release/windows/amd64/drone-docker.exe C:/bin/drone-docker.exe
ENTRYPOINT [ "C:\\bin\\drone-docker.exe" ]

View File

@@ -24,7 +24,7 @@ manifests:
os: linux os: linux
variant: v7 variant: v7
- -
image: plugins/docker:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803 image: plugins/docker:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
@@ -41,3 +41,9 @@ manifests:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1903 version: 1903
-
image: plugins/docker:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
platform:
architecture: amd64
os: windows
version: 1909

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1803 FROM plugins/docker:windows-1803-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ECR" ` org.label-schema.name="Drone ECR" `

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1809 FROM plugins/docker:windows-1809-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ECR" ` org.label-schema.name="Drone ECR" `

View File

@@ -0,0 +1,10 @@
# escape=`
FROM plugins/docker:windows-1909-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone ECR" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-ecr.exe C:/bin/drone-ecr.exe
ENTRYPOINT [ "C:\\bin\\drone-ecr.exe" ]

View File

@@ -24,14 +24,26 @@ manifests:
os: linux os: linux
variant: v7 variant: v7
- -
image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803 image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1803 version: 1803
- -
image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1809 version: 1809
-
image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1903-amd64
platform:
architecture: amd64
os: windows
version: 1903
-
image: plugins/ecr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
platform:
architecture: amd64
os: windows
version: 1909

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1803 FROM plugins/docker:windows-1803-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone GCR" ` org.label-schema.name="Drone GCR" `

View File

@@ -1,5 +1,5 @@
# escape=` # escape=`
FROM plugins/docker:windows-1809 FROM plugins/docker:windows-1809-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" ` LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone GCR" ` org.label-schema.name="Drone GCR" `

View File

@@ -0,0 +1,10 @@
# escape=`
FROM plugins/docker:windows-1909-amd64
LABEL maintainer="Drone.IO Community <drone-dev@googlegroups.com>" `
org.label-schema.name="Drone GCR" `
org.label-schema.vendor="Drone.IO Community" `
org.label-schema.schema-version="1.0"
ADD release/windows/amd64/drone-gcr.exe C:/bin/drone-gcr.exe
ENTRYPOINT [ "C:\\bin\\drone-gcr.exe" ]

View File

@@ -24,14 +24,20 @@ manifests:
os: linux os: linux
variant: v7 variant: v7
- -
image: plugins/gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803 image: plugins/gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1803-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1803 version: 1803
- -
image: plugins/gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809 image: plugins/gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1809-amd64
platform: platform:
architecture: amd64 architecture: amd64
os: windows os: windows
version: 1809 version: 1809
-
image: plugins/gcr:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}windows-1909-amd64
platform:
architecture: amd64
os: windows
version: 1909

21
go.mod
View File

@@ -1,14 +1,21 @@
module github.com/drone-plugins/drone-docker module github.com/drone-plugins/drone-docker
require ( require (
github.com/aws/aws-sdk-go v1.16.15 github.com/aws/aws-sdk-go v1.26.7
github.com/coreos/go-semver v0.2.0 github.com/coreos/go-semver v0.3.0
github.com/joho/godotenv v1.3.0 github.com/joho/godotenv v1.3.0
github.com/sirupsen/logrus v1.3.0 github.com/sirupsen/logrus v1.3.0
github.com/urfave/cli v1.20.0 github.com/urfave/cli v1.22.2
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e // indirect
golang.org/x/text v0.3.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
) )
replace github.com/urfave/cli => github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77 require (
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.1 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 // indirect
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 // indirect
)
go 1.17

26
go.sum
View File

@@ -1,9 +1,10 @@
github.com/aws/aws-sdk-go v1.16.15 h1:kQyxfRyjAwIYjf0225sn/pn+WAlncKyI8dmT3+ItMFE= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/aws/aws-sdk-go v1.16.15/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.26.7 h1:ObjEnmzvSdYy8KVd3me7v/UMyCn81inLy2SyoIPoBkg=
github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77 h1:bXc5tB7PFVzIHUfTECDt0Orw6mIAzHePWBmemvtnfiU= github.com/aws/aws-sdk-go v1.26.7/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/bradrydzewski/cli v0.0.0-20190108225652-0d51abd87c77/go.mod h1:4SmsVk3pOgYeJlG54e23Ztd/HucXeH5RmH5bNO+uOpk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM=
github.com/coreos/go-semver v0.2.0 h1:3Jm3tLmsgAYcjC+4Up7hJrFBPr+n7rAqYeSw/SZazuY= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM= github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
@@ -14,22 +15,21 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME= github.com/sirupsen/logrus v1.3.0 h1:hI/7Q+DtNZ2kINb6qt/lS+IyXnHQe9e90POfeewL/ME=
github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= github.com/sirupsen/logrus v1.3.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793 h1:u+LnwYTOOW7Ukr/fppxEb1Nwz0AtPflrblfvUudpo+I=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33 h1:I6FyU15t786LL7oL/hn43zqTuEGr4PN7F4XJ1p4E3Y8=
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
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/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

View File

@@ -5,7 +5,7 @@ local test_pipeline_name = 'testing';
local windows(os) = os == 'windows'; local windows(os) = os == 'windows';
local golang_image(os, version) = local golang_image(os, version) =
'golang:' + '1.11' + if windows(os) then '-windowsservercore-' + version else ''; 'golang:' + '1.13' + if windows(os) then '-windowsservercore-' + version else '';
{ {
test(os='linux', arch='amd64', version=''):: test(os='linux', arch='amd64', version='')::

View File

@@ -0,0 +1,35 @@
# this script is used by the continuous integration server to
# build and publish the docker image for a commit to master.
$ErrorActionPreference = "Stop"
$env:GOOS="windows"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
if (-not (Test-Path env:VERSION)) {
$env:VERSION="1809"
}
if (-not (Test-Path env:REGISTRY)) {
$env:REGISTRY="docker"
}
echo $env:GOOS
echo $env:GOARCH
echo $env:VERSION
echo $env:REGISTRY
# build the binary
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe";
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
# build and publish the docker image
docker login -u ${env:USERNAME} -p ${env:PASSWORD}
Write-Host "+ docker build -f docker/${env:REGISTRY}/Dockerfile.windows.amd64.${env:VERSION} -t plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64 .";
docker build -f docker/${env:REGISTRY}/Dockerfile.windows.amd64.${env:VERSION} -t plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64 .
Write-Host "+ docker push plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64"
docker push plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64
# remove images from local cache
Write-Host "+ docker rmi plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64"
docker rmi plugins/${env:REGISTRY}:windows-${env:VERSION}-amd64

66
scripts/windows/tag.ps1 Normal file
View File

@@ -0,0 +1,66 @@
# this script is used by the continuous integration server to
# build and publish the docker image for a tagged revsision.
$ErrorActionPreference = "Stop"
$env:GOOS="windows"
$env:GOARCH="amd64"
$env:CGO_ENABLED="0"
if (-not (Test-Path env:VERSION)) {
$env:VERSION="1809"
}
if (-not (Test-Path env:DRONE_SEMVER_SHORT)) {
echo "missing semver"
exit 1
}
if (-not (Test-Path env:REGISTRY)) {
$env:REGISTRY="docker"
}
# define the image tags
$env:IMAGE_PATCH="plugins/${env:REGISTRY}:${env:DRONE_SEMVER_SHORT}-windows-${env:VERSION}-amd64"
$env:IMAGE_MAJOR="plugins/${env:REGISTRY}:${env:DRONE_SEMVER_MAJOR}-windows-${env:VERSION}-amd64"
$env:IMAGE_MINOR="plugins/${env:REGISTRY}:${env:DRONE_SEMVER_MAJOR}.${env:DRONE_SEMVER_MINOR}-windows-${env:VERSION}-amd64"
echo "build environment:"
echo $env:GOOS
echo $env:GOARCH
echo $env:VERSION
# build the binary
Write-Host "+ go build -o release/windows/amd64/drone-${env:REGISTRY}.exe"
go build -o release/windows/amd64/drone-${env:REGISTRY}.exe ./cmd/drone-${env:REGISTRY}
# authenticate with the docker registry
docker login -u ${env:USERNAME} -p ${env:PASSWORD}
echo "building images:"
echo ${env:IMAGE_PATCH}
echo ${env:IMAGE_MINOR}
echo ${env:IMAGE_MAJOR}
# build and tag the docker images
Write-Host "+ docker build -f docker/${env:REGISTRY}/Dockerfile.windows.amd64.${env:VERSION} -t ${env:IMAGE_PATCH} ."
docker build -f docker/${env:REGISTRY}/Dockerfile.windows.amd64.${env:VERSION} -t ${env:IMAGE_PATCH} .
Write-Host "+ docker tag ${env:IMAGE_PATCH} ${env:IMAGE_MAJOR}"
docker tag ${env:IMAGE_PATCH} ${env:IMAGE_MAJOR}
Write-Host "+ docker tag ${env:IMAGE_PATCH} ${env:IMAGE_MINOR}"
docker tag ${env:IMAGE_PATCH} ${env:IMAGE_MINOR}
# publish the docker images
Write-Host "+ docker push ${env:IMAGE_MAJOR}"
docker push ${env:IMAGE_MAJOR}
Write-Host "+ docker push ${env:IMAGE_MINOR}"
docker push ${env:IMAGE_MINOR}
Write-Host "+ docker push ${env:IMAGE_PATCH}"
docker push ${env:IMAGE_PATCH}
# remove images after from local cache
Write-Host "+ docker rmi ${env:IMAGE_MAJOR}"
docker rmi ${env:IMAGE_MAJOR}
Write-Host "+ docker rmi ${env:IMAGE_MINOR}"
docker rmi ${env:IMAGE_MINOR}
Write-Host "+ docker rmi ${env:IMAGE_PATCH}"
docker rmi ${env:IMAGE_PATCH}

23
tags.go
View File

@@ -9,10 +9,13 @@ import (
// DefaultTagSuffix returns a set of default suggested tags // DefaultTagSuffix returns a set of default suggested tags
// based on the commit ref with an attached suffix. // based on the commit ref with an attached suffix.
func DefaultTagSuffix(ref, suffix string) []string { func DefaultTagSuffix(ref, suffix string) ([]string, error) {
tags := DefaultTags(ref) tags, err := DefaultTags(ref)
if err != nil {
return nil, err
}
if len(suffix) == 0 { if len(suffix) == 0 {
return tags return tags, nil
} }
for i, tag := range tags { for i, tag := range tags {
if tag == "latest" { if tag == "latest" {
@@ -21,7 +24,7 @@ func DefaultTagSuffix(ref, suffix string) []string {
tags[i] = fmt.Sprintf("%s-%s", tag, suffix) tags[i] = fmt.Sprintf("%s-%s", tag, suffix)
} }
} }
return tags return tags, nil
} }
func splitOff(input string, delim string) string { func splitOff(input string, delim string) string {
@@ -36,19 +39,19 @@ func splitOff(input string, delim string) string {
// DefaultTags returns a set of default suggested tags based on // DefaultTags returns a set of default suggested tags based on
// the commit ref. // the commit ref.
func DefaultTags(ref string) []string { func DefaultTags(ref string) ([]string, error) {
if !strings.HasPrefix(ref, "refs/tags/") { if !strings.HasPrefix(ref, "refs/tags/") {
return []string{"latest"} return []string{"latest"}, nil
} }
v := stripTagPrefix(ref) v := stripTagPrefix(ref)
version, err := semver.NewVersion(v) version, err := semver.NewVersion(v)
if err != nil { if err != nil {
return []string{"latest"} return []string{"latest"}, err
} }
if version.PreRelease != "" || version.Metadata != "" { if version.PreRelease != "" || version.Metadata != "" {
return []string{ return []string{
version.String(), version.String(),
} }, nil
} }
v = stripTagPrefix(ref) v = stripTagPrefix(ref)
@@ -59,13 +62,13 @@ func DefaultTags(ref string) []string {
return []string{ return []string{
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor), fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch), fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch),
} }, nil
} }
return []string{ return []string{
fmt.Sprintf("%0*d", len(dotParts[0]), version.Major), fmt.Sprintf("%0*d", len(dotParts[0]), version.Major),
fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor), fmt.Sprintf("%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor),
fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch), fmt.Sprintf("%0*d.%0*d.%0*d", len(dotParts[0]), version.Major, len(dotParts[1]), version.Minor, len(dotParts[2]), version.Patch),
} }, nil
} }
// UseDefaultTag for keep only default branch for latest tag // UseDefaultTag for keep only default branch for latest tag

View File

@@ -34,20 +34,35 @@ func TestDefaultTags(t *testing.T) {
{"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}}, {"refs/tags/1.0.0", []string{"1", "1.0", "1.0.0"}},
{"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}}, {"refs/tags/v1.0.0", []string{"1", "1.0", "1.0.0"}},
{"refs/tags/v1.0.0-alpha.1", []string{"1.0.0-alpha.1"}}, {"refs/tags/v1.0.0-alpha.1", []string{"1.0.0-alpha.1"}},
// malformed or errors
{"refs/tags/x1.0.0", []string{"latest"}},
{"v1.0.0", []string{"latest"}},
} }
for _, test := range tests { for _, test := range tests {
got, want := DefaultTags(test.Before), test.After tags, err := DefaultTags(test.Before)
if err != nil {
t.Error(err)
continue
}
got, want := tags, test.After
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("Got tag %v, want %v", got, want) t.Errorf("Got tag %v, want %v", got, want)
} }
} }
} }
func TestDefaultTagsError(t *testing.T) {
var tests = []string{
"refs/tags/x1.0.0",
"refs/tags/20190203",
}
for _, test := range tests {
_, err := DefaultTags(test)
if err == nil {
t.Errorf("Expect tag error for %s", test)
}
}
}
func TestDefaultTagSuffix(t *testing.T) { func TestDefaultTagSuffix(t *testing.T) {
var tests = []struct { var tests = []struct {
Before string Before string
@@ -105,7 +120,12 @@ func TestDefaultTagSuffix(t *testing.T) {
} }
for _, test := range tests { for _, test := range tests {
got, want := DefaultTagSuffix(test.Before, test.Suffix), test.After tag, err := DefaultTagSuffix(test.Before, test.Suffix)
if err != nil {
t.Error(err)
continue
}
got, want := tag, test.After
if !reflect.DeepEqual(got, want) { if !reflect.DeepEqual(got, want) {
t.Errorf("Got tag %v, want %v", got, want) t.Errorf("Got tag %v, want %v", got, want)
} }