├── .github └── workflows │ └── main.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── cmd ├── build.go ├── build_push.go ├── login.go ├── main.go └── push.go ├── docker.Makefile ├── e2e ├── Dockerfile.registry ├── build_push_test.go ├── build_test.go ├── helper_test.go ├── login_test.go ├── push_test.go └── testdata │ ├── auth │ └── htpasswd │ ├── build_push_tests │ ├── Dockerfile │ ├── build_push.env │ ├── build_push_from_registry.env │ └── fromreg.Dockerfile │ ├── build_tests │ ├── Dockerfile │ ├── auto_labels.env │ ├── static_labels.env │ ├── static_tags.env │ ├── tag_branch.env │ ├── tag_master.env │ ├── tag_pr.env │ └── tag_tag.env │ ├── login_test.env │ └── push_tests │ ├── Dockerfile │ └── push.env ├── go.mod ├── go.sum ├── golangci.yml └── internal ├── command ├── args.go ├── args_test.go └── runner.go └── options ├── build.go ├── build_test.go ├── github.go ├── github_test.go ├── helper.go ├── login.go ├── login_test.go ├── push.go ├── push_test.go ├── registry.go ├── registry_test.go ├── tag.go └── tag_test.go /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | tags: 8 | - '*' 9 | pull_request: 10 | 11 | jobs: 12 | build: 13 | name: build 14 | runs-on: ubuntu-latest 15 | timeout-minutes: 5 16 | steps: 17 | 18 | - name: Checkout 19 | uses: actions/checkout@v2 20 | 21 | - name: build and test code 22 | run: DOCKER_BUILDKIT=1 make -f docker.Makefile all 23 | 24 | - name: build and push image 25 | uses: docker/build-push-action@v1 26 | env: 27 | DOCKER_BUILDKIT: 1 28 | with: 29 | username: ${{ secrets.DOCKER_USERNAME }} 30 | password: ${{ secrets.DOCKER_PASSWORD }} 31 | repository: docker/github-actions 32 | tag_with_ref: true 33 | add_git_labels: true 34 | build_args: MAKE_TARGET=build 35 | push: ${{ startsWith(github.ref, 'refs/tags/') }} 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | ARG GO_VERSION=1.13.7 2 | ARG GOLANGCI_LINT_VERSION=v1.23.6 3 | ARG DND_VERSION=19.03 4 | 5 | 6 | # Builds the github-actions binary, checks linting, and runs unit level tests 7 | FROM golang:${GO_VERSION} AS builder 8 | 9 | RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} 10 | 11 | ARG MAKE_TARGET=default 12 | ENV CGO_ENABLED=0 13 | WORKDIR /src 14 | 15 | COPY . . 16 | 17 | RUN make ${MAKE_TARGET} 18 | 19 | 20 | # Used to run e2e tests for github-actions 21 | # This image must be run as a container to run the tests 22 | FROM golang:${GO_VERSION} AS e2e 23 | ARG CLI_CHANNEL=stable 24 | ARG CLI_VERSION=19.03.5 25 | 26 | RUN apt-get install -y -q --no-install-recommends coreutils util-linux 27 | 28 | ENV CGO_ENABLED=0 29 | ENV GITHUB_ACTIONS_BINARY=/github-actions 30 | WORKDIR /tests 31 | 32 | RUN curl -fL https://download.docker.com/linux/static/${CLI_CHANNEL}/x86_64/docker-${CLI_VERSION}.tgz | tar xzO docker/docker > /usr/bin/docker && chmod +x /usr/bin/docker 33 | 34 | COPY . . 35 | COPY --from=builder /src/bin/github-actions /github-actions 36 | 37 | 38 | # Used to extract the github-actions binary 39 | FROM scratch AS cli 40 | COPY --from=builder /src/bin/github-actions github-actions 41 | 42 | 43 | # The github-actions image that is used by published docker github actions 44 | FROM docker:${DND_VERSION} 45 | 46 | COPY --from=builder /src/bin/github-actions /github-actions 47 | 48 | ENTRYPOINT ["/github-actions"] 49 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | https://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | Copyright 2013-2018 Docker, Inc. 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | https://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | default: build lint test-unit 2 | 3 | all: default test-e2e 4 | 5 | build: 6 | @$(call mkdir,bin) 7 | go build -o bin/github-actions ./cmd 8 | 9 | lint: 10 | golangci-lint run --config golangci.yml ./... 11 | 12 | test: test-unit test-e2e 13 | 14 | test-unit: 15 | go test ./cmd/... ./internal/... 16 | 17 | test-e2e: build 18 | docker build --file ./e2e/Dockerfile.registry -t github-actions-registry ./e2e 19 | go test ./e2e/... 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Deprecated 2 | 3 | This repository is being replaced with [docker/build-push-action@v2](https://github.com/docker/build-push-action/) 4 | which includes significant changes and now uses Docker [Buildx](https://github.com/docker/buildx). It will not receive 5 | any future updates, please update your workflows. 6 | 7 | [Upgrade notes](https://github.com/docker/build-push-action/blob/master/UPGRADE.md) with many [usage examples](https://github.com/docker/build-push-action/#advanced-usage) 8 | have been added to handle most use cases. 9 | 10 | ## About 11 | 12 | The core code base for Docker's GitHub Actions (https://github.com/features/actions). This code is used to build the docker/github-actions image that provides the functionality used by the published Docker GitHub Action: 13 | 14 | * [Build and push Docker images action](https://github.com/docker/build-push-action) 15 | 16 | `github-actions` runs a command line tool that shells out to docker to perform the various functions. Parameters are supplied to `github-actions` using environment variables in the form described by the GitHub Actions documentation. `github-actions` uses some of the default GitHub Actions environment variables as described in the individual commands section. 17 | 18 | ## Commands 19 | 20 | Commands can be called using `docker run docker/github-actions {command}` 21 | 22 | ### login 23 | 24 | Does a `docker login` using the supplied username and password. Will default to Docker Hub but can be supplied a server address to login to a third-party registry as required. 25 | 26 | #### inputs 27 | 28 | |Environment Variable|Required|Description| 29 | |---|---|---| 30 | |INPUT_USERNAME|yes|Username to login with| 31 | |INPUT_PASSWORD|yes|Password to login with| 32 | |INPUT_REGISTRY|no|Registry server to login to. Defaults to Docker Hub| 33 | 34 | ### build 35 | 36 | Builds and tags a docker image. 37 | 38 | #### inputs 39 | 40 | |Environment Variable|Required|Description| 41 | |---|---|---| 42 | |INPUT_PATH|yes|Path to build from| 43 | |INPUT_DOCKERFILE|no|Path to Dockerfile| 44 | |INPUT_ADD_GIT_LABELS|no|Adds git labels (see below)| 45 | |INPUT_TARGET|no|Target build stage to build| 46 | |INPUT_BUILD_ARGS|no|Comma-delimited list of build-args| 47 | |INPUT_LABELS|no|Comma-delimited list of labels| 48 | |INPUT_CACHE_FROMS|no|Comma-delimited list of cache-froms| 49 | 50 | See the tagging section for information on tag inputs 51 | 52 | ##### Git labels 53 | 54 | When `INPUT_ADD_GIT_LABELS` is `true` labels are automatically added to the image that contain data about the current state of the git repo based on the standards set out in https://github.com/opencontainers/image-spec/blob/master/annotations.md. 55 | 56 | 3 labels are supported: 57 | 58 | |Label|Description| 59 | |---|---| 60 | |org.opencontainers.image.created|Date and time on which the image was built (string, date-time as defined by RFC 3339).| 61 | |org.opencontainers.image.source|URL to this repository. E.g. `https://github.com/myorg/myrepository`| 62 | |org.opencontainers.image.revision|The full git sha of this commit.| 63 | 64 | ### push 65 | 66 | Pushes a docker image. 67 | 68 | #### inputs 69 | 70 | See the tagging section for information on tag inputs 71 | 72 | 73 | ### build-push 74 | 75 | Builds, logs in, and pushes a docker image. 76 | 77 | #### inputs 78 | 79 | Same as the login and build commands with the addition of 80 | 81 | |Environment Variable|Required|Description| 82 | |---|---|---| 83 | |INPUT_PUSH|no|Will push the image if true| 84 | 85 | 86 | ## Tagging 87 | 88 | Tagging of images can be set manually, left to `github-actions` to automate, or a combination of the both. 89 | 90 | There are 4 input variables used for tagging 91 | 92 | |Environment Variable|Required|Description| 93 | |---|---|---| 94 | |INPUT_REGISTRY|no|Registry server to tag with| 95 | |INPUT_REPOSITORY|yes|Repository to tag with| 96 | |INPUT_TAGS|no|Hard coded comma-delimited list of tags| 97 | |INPUT_TAG_WITH_REF|no|If true then `github-actions` will add tags depending on the git ref automatically as described below| 98 | |INPUT_TAG_WITH_SHA|no|If true then `github-actions` will add a tag in the form `sha-{git-short-sha}`| 99 | 100 | If `INPUT_REGISTRY` is set then all tags are prefixed with `{INPUT_REGISTRY}/{INPUT_REPOSITORY}:`. 101 | If not then all tags are prefixed with `{INPUT_REPOSITORY}:` 102 | 103 | Auto tags depend on the git reference that the run is associated with. The reference is passed to `github-actions` using the GitHub actions `GITHUB_REF` enviroment variable. 104 | 105 | If the reference is `refs/heads/{branch-name}` then the tag `{branch-name}` is added. For the master branch the `{branch-name}` is replaced with `latest`. 106 | 107 | If the reference is `refs/pull/{pr}` then the tag `pr-{pr}` is added. 108 | 109 | If the reference is `refs/tags/{tag-name}` then the tag `{tag-name}` is added. 110 | 111 | Any `/` in the auto tags are replaced with `-`. 112 | 113 | For example if the environment variables are as follows: 114 | 115 | |Variable|Value| 116 | |---|---| 117 | |INPUT_REGISTRY|| 118 | |INPUT_REPOSITORY|myorg/myimage| 119 | |INPUT_TAGS|foo,bar| 120 | |INPUT_TAG_WITH_REF|true| 121 | |GITHUB_REF|refs/tags/v0.1| 122 | 123 | Then the image will be tagged with: 124 | ``` 125 | myorg/myimage:foo 126 | myorg/myimage:bar 127 | myorg/myimage:v0.1 128 | ``` 129 | 130 | If the variables are as follows: 131 | 132 | |Variable|Value| 133 | |---|---| 134 | |INPUT_REGISTRY|myregistry| 135 | |INPUT_REPOSITORY|myorg/myimage| 136 | |INPUT_TAGS|foo,bar| 137 | |INPUT_TAG_WITH_REF|true| 138 | |INPUT_TAG_WITH_SHA|true| 139 | |GITHUB_REF|refs/heads/master| 140 | |GITHUB_SHA|c6df8c68eb71799f9c9ab4a4a4650d6aabd7e415| 141 | 142 | Then the image will be tagged with: 143 | ``` 144 | myregistry/myorg/myimage:foo 145 | myregistry/myorg/myimage:bar 146 | myregistry/myorg/myimage:lastest 147 | myregistry/myorg/myimage:sha-c6df8c6 148 | ``` 149 | 150 | ## Building github-actions 151 | The code is written in Go v1.13 with `go mod`. It can be built locally using the `Makefile` or in docker using the `docker.Makefile`. 152 | 153 | `make -f docker.Makefile` will build the code, check the linting using golangci-lint, run the go tests, and build the image with a tag of docker/github-actions:latest 154 | 155 | `make -f docker.Makefile image` will build the github-actions image without a tag and without running test or lint checking 156 | 157 | `make -f docker.Makefile cli` will build the cli and copy it to `./bin/github-actions` 158 | 159 | `make -f docker.Makefile test` will run the unit and e2e tests 160 | -------------------------------------------------------------------------------- /cmd/build.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/docker/github-actions/internal/command" 5 | "github.com/docker/github-actions/internal/options" 6 | ) 7 | 8 | func build(cmd command.Runner) error { 9 | o, err := options.GetBuildOptions() 10 | if err != nil { 11 | return err 12 | } 13 | 14 | github, err := options.GetGitHubOptions() 15 | if err != nil { 16 | return err 17 | } 18 | 19 | tags, err := options.GetTags(options.GetRegistry(), github) 20 | if err != nil { 21 | return err 22 | } 23 | 24 | return command.RunBuild(cmd, o, github, tags) 25 | } 26 | -------------------------------------------------------------------------------- /cmd/build_push.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/docker/github-actions/internal/command" 7 | "github.com/docker/github-actions/internal/options" 8 | ) 9 | 10 | func buildPush(cmd command.Runner) error { 11 | registry := options.GetRegistry() 12 | login, err := options.GetLoginOptions() 13 | if err != nil { 14 | return err 15 | } 16 | if login.Username != "" && login.Password != "" { 17 | if err := command.RunLogin(cmd, login, registry); err != nil { 18 | return err 19 | } 20 | } 21 | 22 | github, err := options.GetGitHubOptions() 23 | if err != nil { 24 | return err 25 | } 26 | 27 | tags, err := options.GetTags(registry, github) 28 | if err != nil { 29 | return err 30 | } 31 | 32 | build, err := options.GetBuildOptions() 33 | if err != nil { 34 | return err 35 | } 36 | if err = command.RunBuild(cmd, build, github, tags); err != nil { 37 | return err 38 | } 39 | 40 | if shouldPush, err := options.ShouldPush(); err != nil { 41 | return err 42 | } else if shouldPush { 43 | return command.RunPush(cmd, tags) 44 | } 45 | 46 | fmt.Println("Skipping push") 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /cmd/login.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/docker/github-actions/internal/command" 5 | "github.com/docker/github-actions/internal/options" 6 | ) 7 | 8 | func login(cmd command.Runner) error { 9 | o, err := options.GetLoginOptions() 10 | if err != nil { 11 | return err 12 | } 13 | 14 | return command.RunLogin(cmd, o, options.GetRegistry()) 15 | } 16 | -------------------------------------------------------------------------------- /cmd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | "github.com/docker/github-actions/internal/command" 8 | "github.com/spf13/cobra" 9 | ) 10 | 11 | func main() { 12 | runner := command.NewRunner() 13 | 14 | rootCmd := &cobra.Command{ 15 | Use: "github-actions", 16 | Short: "Used in GitHub Actions to run Docker workflows", 17 | } 18 | rootCmd.AddCommand( 19 | &cobra.Command{ 20 | Use: "login", 21 | Short: "Logs into a docker registry", 22 | RunE: func(cmd *cobra.Command, args []string) error { 23 | return login(runner) 24 | }, 25 | }, 26 | &cobra.Command{ 27 | Use: "build", 28 | Short: "Builds a docker image", 29 | RunE: func(cmd *cobra.Command, args []string) error { 30 | return build(runner) 31 | }, 32 | }, 33 | &cobra.Command{ 34 | Use: "push", 35 | Short: "Pushes a docker image", 36 | RunE: func(cmd *cobra.Command, args []string) error { 37 | return push(runner) 38 | }, 39 | }, 40 | &cobra.Command{ 41 | Use: "build-push", 42 | Short: "Builds and pushes a docker image to a registry, logging in if necessary", 43 | RunE: func(cmd *cobra.Command, args []string) error { 44 | return buildPush(runner) 45 | }, 46 | }, 47 | ) 48 | 49 | if err := rootCmd.Execute(); err != nil { 50 | fmt.Println(err) 51 | os.Exit(1) 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /cmd/push.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/docker/github-actions/internal/command" 5 | "github.com/docker/github-actions/internal/options" 6 | ) 7 | 8 | func push(cmd command.Runner) error { 9 | github, err := options.GetGitHubOptions() 10 | if err != nil { 11 | return err 12 | } 13 | tags, err := options.GetTags(options.GetRegistry(), github) 14 | if err != nil { 15 | return err 16 | } 17 | return command.RunPush(cmd, tags) 18 | } 19 | -------------------------------------------------------------------------------- /docker.Makefile: -------------------------------------------------------------------------------- 1 | TAG ?= latest 2 | DOCKER_BUILD = docker build --progress=plain 3 | 4 | ROOT_DIR = $(dir $(realpath $(firstword $(MAKEFILE_LIST)))) 5 | ROOT_DIR := $(subst .\,,$(ROOT_DIR)) 6 | 7 | all: build test-e2e 8 | 9 | build: 10 | $(DOCKER_BUILD) -t docker/github-actions-default --build-arg MAKE_TARGET=default . 11 | 12 | image: 13 | $(DOCKER_BUILD) -t docker/github-actions:$(TAG) --build-arg MAKE_TARGET=build . 14 | 15 | cli: 16 | @$(call mkdir,bin) 17 | $(DOCKER_BUILD) -t github-actions-cli --target=cli --output type=local,dest=./bin/ --build-arg MAKE_TARGET=build . 18 | 19 | lint: 20 | $(DOCKER_BUILD) -t github-actions-lint --target=builder --build-arg MAKE_TARGET=lint . 21 | 22 | test: test-unit test-e2e 23 | 24 | test-unit: 25 | $(DOCKER_BUILD) -t github-actions-test-unit --target=builder --build-arg MAKE_TARGET=test-unit . 26 | 27 | test-e2e: 28 | $(DOCKER_BUILD) -t github-actions-test-e2e --target e2e --build-arg MAKE_TARGET=build . 29 | docker run --rm --network="host" -v /var/run/docker.sock:/var/run/docker.sock github-actions-test-e2e make test-e2e 30 | -------------------------------------------------------------------------------- /e2e/Dockerfile.registry: -------------------------------------------------------------------------------- 1 | FROM registry:2 2 | 3 | ENV REGISTRY_AUTH=htpasswd 4 | ENV REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm" 5 | ENV REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd 6 | 7 | COPY ./testdata/auth/htpasswd /auth/htpasswd 8 | -------------------------------------------------------------------------------- /e2e/build_push_test.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "os/exec" 5 | "sort" 6 | "testing" 7 | 8 | "gotest.tools/v3/assert" 9 | ) 10 | 11 | func testBuildPush(t *testing.T, envFile string, tags []string, labels map[string]string) { 12 | err := removeImages(tags) 13 | assert.NilError(t, err) 14 | 15 | err = runActionsCommand("build-push", envFile) 16 | assert.NilError(t, err) 17 | 18 | err = removeImages(tags) 19 | assert.NilError(t, err) 20 | 21 | for _, tag := range tags { 22 | err = exec.Command("docker", "pull", tag).Run() 23 | assert.NilError(t, err) 24 | } 25 | 26 | for _, tag := range tags { 27 | assertBuildPushImages(t, tag, tags, labels) 28 | } 29 | } 30 | 31 | func TestBuildPush(t *testing.T) { 32 | err := setupLocalRegistry() 33 | assert.NilError(t, err) 34 | defer removeLocalRegistry() 35 | 36 | err = ensureLocalRegistryAlive() 37 | assert.NilError(t, err) 38 | 39 | // Build and push base image 40 | baseTags := []string{ 41 | "localhost:5000/org/base:build-push-tag1", 42 | "localhost:5000/org/base:build-push-test", 43 | } 44 | defer removeImages(baseTags) 45 | testBuildPush( 46 | t, 47 | "testdata/build_push_tests/build_push.env", 48 | baseTags, 49 | map[string]string{ 50 | "a": "a1", 51 | }, 52 | ) 53 | 54 | err = logoutLocalRegistry() 55 | assert.NilError(t, err) 56 | 57 | // Build and push image using base image from local registry 58 | testBuildPush( 59 | t, 60 | "testdata/build_push_tests/build_push_from_registry.env", 61 | []string{ 62 | "localhost:5000/org/repo:build-push-reg-tag1", 63 | "localhost:5000/org/repo:build-push-reg-test", 64 | }, 65 | map[string]string{ 66 | "a": "a1", 67 | "b": "b1", 68 | }, 69 | ) 70 | } 71 | 72 | func assertBuildPushImages(t *testing.T, image string, expectedTags []string, expectedLabels map[string]string) { 73 | inspect, err := inspectImage(image) 74 | assert.NilError(t, err) 75 | 76 | repoTags := inspect.RepoTags 77 | sort.Strings(repoTags) 78 | 79 | assert.DeepEqual(t, expectedTags, repoTags) 80 | assert.DeepEqual(t, expectedLabels, inspect.Config.Labels) 81 | } 82 | 83 | func ensureLocalRegistryAlive() error { 84 | if err := loginLocalRegistry(); err != nil { 85 | return err 86 | } 87 | 88 | return logoutLocalRegistry() 89 | } 90 | 91 | func logoutLocalRegistry() error { 92 | return exec.Command("docker", "logout", "localhost:5000").Run() 93 | } 94 | -------------------------------------------------------------------------------- /e2e/build_test.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "os/exec" 5 | "testing" 6 | "time" 7 | 8 | "github.com/hashicorp/go-multierror" 9 | "gotest.tools/v3/assert" 10 | ) 11 | 12 | func TestBuild(t *testing.T) { 13 | testCases := []struct { 14 | name string 15 | envFile string 16 | expectedTags []string 17 | expectedLabels map[string]string 18 | }{ 19 | { 20 | name: "static-tags", 21 | envFile: "testdata/build_tests/static_tags.env", 22 | expectedTags: []string{ 23 | "localhost:5000/my-repository:v1-static-tags", 24 | "localhost:5000/my-repository:v1.1-static-tags", 25 | }, 26 | }, 27 | { 28 | name: "static-labels", 29 | envFile: "testdata/build_tests/static_labels.env", 30 | expectedTags: []string{ 31 | "localhost:5000/my-repository:static-labels", 32 | }, 33 | expectedLabels: map[string]string{ 34 | "a": "a1", 35 | "b": "b1", 36 | }, 37 | }, 38 | { 39 | name: "auto-tags-master", 40 | envFile: "testdata/build_tests/tag_master.env", 41 | expectedTags: []string{ 42 | "localhost:5000/my-repository:auto-tags-master", 43 | "localhost:5000/my-repository:latest", 44 | }, 45 | }, 46 | { 47 | name: "auto-tags-branch", 48 | envFile: "testdata/build_tests/tag_branch.env", 49 | expectedTags: []string{ 50 | "localhost:5000/my-repository:auto-tags-branch", 51 | "localhost:5000/my-repository:branch", 52 | }, 53 | }, 54 | { 55 | name: "auto-tags-pr", 56 | envFile: "testdata/build_tests/tag_pr.env", 57 | expectedTags: []string{ 58 | "localhost:5000/my-repository:pr-pr1", 59 | }, 60 | }, 61 | { 62 | name: "auto-tags-tag", 63 | envFile: "testdata/build_tests/tag_tag.env", 64 | expectedTags: []string{ 65 | "localhost:5000/my-repository:tag1", 66 | }, 67 | }, 68 | } 69 | 70 | for _, tc := range testCases { 71 | tc := tc 72 | t.Run(tc.name, func(t *testing.T) { 73 | err := runActionsCommand("build", tc.envFile) 74 | assert.NilError(t, err) 75 | defer removeImages(tc.expectedTags) 76 | 77 | for _, tag := range tc.expectedTags { 78 | inspect, err := inspectImage(tag) 79 | assert.NilError(t, err) 80 | assert.DeepEqual(t, tc.expectedTags, inspect.RepoTags) 81 | assert.DeepEqual(t, tc.expectedLabels, inspect.Config.Labels) 82 | } 83 | }) 84 | } 85 | } 86 | 87 | func TestBuildWithGitLabels(t *testing.T) { 88 | tags := []string{"localhost:5000/my-repository:auto-labels"} 89 | err := runActionsCommand("build", "testdata/build_tests/auto_labels.env") 90 | assert.NilError(t, err) 91 | defer removeImages(tags) 92 | 93 | inspect, err := inspectImage(tags[0]) 94 | assert.NilError(t, err) 95 | assert.DeepEqual(t, tags, inspect.RepoTags) 96 | 97 | assert.Equal(t, 4, len(inspect.Config.Labels)) 98 | assert.Equal(t, "a1", inspect.Config.Labels["a"]) 99 | assert.Equal(t, "https://github.com/git/repository", inspect.Config.Labels["org.opencontainers.image.source"]) 100 | assert.Equal(t, "sha", inspect.Config.Labels["org.opencontainers.image.revision"]) 101 | 102 | created, err := time.Parse(time.RFC3339, inspect.Config.Labels["org.opencontainers.image.created"]) 103 | assert.NilError(t, err) 104 | assert.Assert(t, created.Before(time.Now())) 105 | } 106 | 107 | func removeImages(tags []string) error { 108 | var result error 109 | for _, tag := range tags { 110 | if err := exec.Command("docker", "rmi", "-f", tag).Run(); err != nil { 111 | result = multierror.Append(result, err) 112 | } 113 | } 114 | return result 115 | } 116 | -------------------------------------------------------------------------------- /e2e/helper_test.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "bufio" 5 | "encoding/json" 6 | "fmt" 7 | "os" 8 | "os/exec" 9 | ) 10 | 11 | const ( 12 | registryContainerName = "github-actions-registry" 13 | githubActionsImage = "github-actions-e2e" 14 | ) 15 | 16 | func readEnvFile(envFile string) ([]string, error) { 17 | var vars []string 18 | 19 | file, err := os.Open(envFile) 20 | if err != nil { 21 | return vars, err 22 | } 23 | defer file.Close() 24 | 25 | scanner := bufio.NewScanner(file) 26 | for scanner.Scan() { 27 | vars = append(vars, scanner.Text()) 28 | } 29 | 30 | path := os.Getenv("PATH") 31 | vars = append(vars, fmt.Sprintf("PATH=%s", path)) 32 | return vars, scanner.Err() 33 | } 34 | 35 | func setupLocalRegistry() error { 36 | _ = removeLocalRegistry() 37 | 38 | cmd := exec.Command("docker", "run", "-d", "-p", "5000:5000", "--name", registryContainerName, registryContainerName) 39 | cmd.Stdout = os.Stdout 40 | cmd.Stderr = os.Stderr 41 | return cmd.Run() 42 | } 43 | 44 | func removeLocalRegistry() error { 45 | return exec.Command("docker", "rm", "-f", registryContainerName).Run() 46 | } 47 | 48 | func runActionsCommand(command, envFile string) error { 49 | vars, err := readEnvFile(envFile) 50 | if err != nil { 51 | return err 52 | } 53 | 54 | bin, err := getActionsBinaryPath() 55 | if err != nil { 56 | return err 57 | } 58 | 59 | cmd := exec.Command(bin, command) 60 | cmd.Env = vars 61 | cmd.Stdout = os.Stdout 62 | cmd.Stderr = os.Stderr 63 | return cmd.Run() 64 | } 65 | 66 | func getActionsBinaryPath() (string, error) { 67 | if path := os.Getenv("GITHUB_ACTIONS_BINARY"); path != "" { 68 | return path, nil 69 | } 70 | 71 | return "../bin/github-actions", nil 72 | } 73 | 74 | func inspectImage(image string) (inspectResult, error) { 75 | out, err := exec.Command("docker", "inspect", image).Output() 76 | if err != nil { 77 | return inspectResult{}, err 78 | } 79 | var result []inspectResult 80 | if err = json.Unmarshal(out, &result); err != nil { 81 | return inspectResult{}, err 82 | } 83 | return result[0], nil 84 | } 85 | 86 | type inspectResult struct { 87 | RepoTags []string `json:"RepoTags"` 88 | Config inspectResultConfig `json:"Config"` 89 | } 90 | 91 | type inspectResultConfig struct { 92 | Labels map[string]string `json:"Labels"` 93 | } 94 | -------------------------------------------------------------------------------- /e2e/login_test.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "gotest.tools/v3/assert" 8 | "k8s.io/apimachinery/pkg/util/wait" 9 | ) 10 | 11 | func TestLogin(t *testing.T) { 12 | err := setupLocalRegistry() 13 | assert.NilError(t, err) 14 | defer removeLocalRegistry() 15 | 16 | err = loginLocalRegistry() 17 | assert.NilError(t, err) 18 | } 19 | 20 | func loginLocalRegistry() error { 21 | // Polls as registry takes a moment to start up 22 | return wait.Poll(2*time.Second, 30*time.Second, func() (bool, error) { 23 | err := runActionsCommand("login", "testdata/login_test.env") 24 | return err == nil, err 25 | }) 26 | } 27 | -------------------------------------------------------------------------------- /e2e/push_test.go: -------------------------------------------------------------------------------- 1 | package e2e 2 | 3 | import ( 4 | "os/exec" 5 | "testing" 6 | 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestPush(t *testing.T) { 11 | err := setupLocalRegistry() 12 | assert.NilError(t, err) 13 | defer removeLocalRegistry() 14 | 15 | err = loginLocalRegistry() 16 | assert.NilError(t, err) 17 | 18 | tags := []string{"localhost:5000/my-repository:push-test"} 19 | 20 | err = removeImages(tags) 21 | assert.NilError(t, err) 22 | 23 | err = runActionsCommand("build", "testdata/push_tests/push.env") 24 | assert.NilError(t, err) 25 | 26 | err = runActionsCommand("push", "testdata/push_tests/push.env") 27 | assert.NilError(t, err) 28 | 29 | err = removeImages(tags) 30 | assert.NilError(t, err) 31 | 32 | err = exec.Command("docker", "pull", tags[0]).Run() 33 | defer removeImages(tags) 34 | assert.NilError(t, err) 35 | 36 | result, err := inspectImage(tags[0]) 37 | assert.NilError(t, err) 38 | assert.DeepEqual(t, 39 | inspectResult{ 40 | RepoTags: tags, 41 | Config: inspectResultConfig{ 42 | Labels: map[string]string{ 43 | "a": "a1", 44 | "b": "b1", 45 | }, 46 | }, 47 | }, result) 48 | } 49 | -------------------------------------------------------------------------------- /e2e/testdata/auth/htpasswd: -------------------------------------------------------------------------------- 1 | my_user:$2y$05$aj/uKGxLnExU9dMOYtDrOOTp6UfLWIt1r9Y3vz9MnkhK/8z8mwUse 2 | 3 | -------------------------------------------------------------------------------- /e2e/testdata/build_push_tests/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | ENTRYPOINT ["echo", "hello-world build-push"] -------------------------------------------------------------------------------- /e2e/testdata/build_push_tests/build_push.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_push_tests 2 | INPUT_DOCKERFILE=./testdata/build_push_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_TAGS=build-push-test 5 | INPUT_LABELS=a=a1 6 | INPUT_REGISTRY=localhost:5000 7 | INPUT_USERNAME=my_user 8 | INPUT_PASSWORD=my_password 9 | INPUT_REPOSITORY=org/base 10 | INPUT_PUSH=true 11 | GITHUB_REF=refs/tags/build-push-tag1 12 | -------------------------------------------------------------------------------- /e2e/testdata/build_push_tests/build_push_from_registry.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_push_tests 2 | INPUT_DOCKERFILE=./testdata/build_push_tests/fromreg.Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_TAGS=build-push-reg-test 5 | INPUT_LABELS=b=b1 6 | INPUT_REGISTRY=localhost:5000 7 | INPUT_USERNAME=my_user 8 | INPUT_PASSWORD=my_password 9 | INPUT_REPOSITORY=org/repo 10 | INPUT_PUSH=true 11 | GITHUB_REF=refs/tags/build-push-reg-tag1 12 | -------------------------------------------------------------------------------- /e2e/testdata/build_push_tests/fromreg.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM localhost:5000/org/base:build-push-test 2 | 3 | ENTRYPOINT ["echo", "hello-world build-push-from-registry"] -------------------------------------------------------------------------------- /e2e/testdata/build_tests/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | ENTRYPOINT ["echo", "hello-world build"] -------------------------------------------------------------------------------- /e2e/testdata/build_tests/auto_labels.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=false 4 | INPUT_ADD_GIT_LABELS=true 5 | INPUT_TAGS=auto-labels 6 | INPUT_LABELS=a=a1 7 | INPUT_REGISTRY=localhost:5000 8 | INPUT_REPOSITORY=my-repository 9 | GITHUB_REPOSITORY=git/repository 10 | GITHUB_SHA=sha 11 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/static_labels.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=false 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_TAGS=static-labels 6 | INPUT_LABELS=a=a1,b=b1 7 | INPUT_REGISTRY=localhost:5000 8 | INPUT_REPOSITORY=my-repository 9 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/static_tags.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=false 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_TAGS=v1-static-tags,v1.1-static-tags 6 | INPUT_REGISTRY=localhost:5000 7 | INPUT_REPOSITORY=my-repository 8 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/tag_branch.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_TAGS=auto-tags-branch 6 | INPUT_REGISTRY=localhost:5000 7 | INPUT_REPOSITORY=my-repository 8 | GITHUB_REF=refs/heads/branch 9 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/tag_master.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_TAGS=auto-tags-master 6 | INPUT_REGISTRY=localhost:5000 7 | INPUT_REPOSITORY=my-repository 8 | GITHUB_REF=refs/heads/master 9 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/tag_pr.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_REGISTRY=localhost:5000 6 | INPUT_REPOSITORY=my-repository 7 | GITHUB_REF=refs/pull/pr1 8 | -------------------------------------------------------------------------------- /e2e/testdata/build_tests/tag_tag.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/build_tests 2 | INPUT_DOCKERFILE=./testdata/build_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=true 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_REGISTRY=localhost:5000 6 | INPUT_REPOSITORY=my-repository 7 | GITHUB_REF=refs/tags/tag1 8 | -------------------------------------------------------------------------------- /e2e/testdata/login_test.env: -------------------------------------------------------------------------------- 1 | INPUT_REGISTRY=localhost:5000 2 | INPUT_USERNAME=my_user 3 | INPUT_PASSWORD=my_password 4 | -------------------------------------------------------------------------------- /e2e/testdata/push_tests/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine 2 | 3 | ENTRYPOINT ["echo", "hello-world push"] -------------------------------------------------------------------------------- /e2e/testdata/push_tests/push.env: -------------------------------------------------------------------------------- 1 | INPUT_PATH=./testdata/push_tests 2 | INPUT_DOCKERFILE=./testdata/push_tests/Dockerfile 3 | INPUT_TAG_WITH_REF=false 4 | INPUT_ADD_GIT_LABELS=false 5 | INPUT_TAGS=push-test 6 | INPUT_LABELS=a=a1,b=b1 7 | INPUT_REGISTRY=localhost:5000 8 | INPUT_REPOSITORY=my-repository 9 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/docker/github-actions 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/caarlos0/env/v6 v6.1.0 7 | github.com/hashicorp/go-multierror v1.0.0 8 | github.com/magiconair/properties v1.8.1 // indirect 9 | github.com/spf13/cobra v0.0.6 10 | gotest.tools/v3 v3.0.2 11 | k8s.io/apimachinery v0.17.3 12 | ) 13 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= 2 | github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= 3 | github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= 4 | github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= 5 | github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0= 6 | github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE= 7 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 8 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 9 | github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= 10 | github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= 11 | github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= 12 | github.com/caarlos0/env/v6 v6.1.0 h1:4FbM+HmZA/Q5wdSrH2kj0KQXm7xnhuO8y3TuOTnOvqc= 13 | github.com/caarlos0/env/v6 v6.1.0/go.mod h1:iUA6X3VCAOwDhoqvgKlTGjjwJzQseIJaFYApUqQkt+8= 14 | github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= 15 | github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= 16 | github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= 17 | github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= 18 | github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= 19 | github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= 20 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= 21 | github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 22 | github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= 23 | github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 24 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 25 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 26 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 27 | github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= 28 | github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= 29 | github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM= 30 | github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc= 31 | github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs= 32 | github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= 33 | github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= 34 | github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 35 | github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= 36 | github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= 37 | github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= 38 | github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= 39 | github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas= 40 | github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0= 41 | github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg= 42 | github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc= 43 | github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I= 44 | github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= 45 | github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= 46 | github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= 47 | github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= 48 | github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= 49 | github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 50 | github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 51 | github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= 52 | github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 53 | github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 54 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 55 | github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 56 | github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= 57 | github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= 58 | github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY= 59 | github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= 60 | github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= 61 | github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 62 | github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 63 | github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY= 64 | github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= 65 | github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= 66 | github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= 67 | github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= 68 | github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= 69 | github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= 70 | github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o= 71 | github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= 72 | github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= 73 | github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= 74 | github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= 75 | github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM= 76 | github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= 77 | github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= 78 | github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= 79 | github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= 80 | github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= 81 | github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= 82 | github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= 83 | github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= 84 | github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= 85 | github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= 86 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 87 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 88 | github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= 89 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 90 | github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= 91 | github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 92 | github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= 93 | github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= 94 | github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= 95 | github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= 96 | github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= 97 | github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 98 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= 99 | github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 100 | github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 101 | github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= 102 | github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= 103 | github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= 104 | github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw= 105 | github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= 106 | github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 107 | github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 108 | github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= 109 | github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= 110 | github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= 111 | github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= 112 | github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 113 | github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= 114 | github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 115 | github.com/pmezard/go-difflib v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 116 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 117 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 118 | github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= 119 | github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= 120 | github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= 121 | github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= 122 | github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= 123 | github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= 124 | github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 125 | github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 126 | github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= 127 | github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= 128 | github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= 129 | github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= 130 | github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 131 | github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= 132 | github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= 133 | github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= 134 | github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= 135 | github.com/spf13/cobra v0.0.6 h1:breEStsVwemnKh2/s6gMvSdMEkwW0sK8vGStnlVBMCs= 136 | github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE= 137 | github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= 138 | github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 139 | github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= 140 | github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= 141 | github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 142 | github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= 143 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 144 | github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 145 | github.com/stretchr/testify v0.0.0-20151208002404-e3a8ff8ce365/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 146 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 147 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 148 | github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= 149 | github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= 150 | github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= 151 | github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= 152 | github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ= 153 | github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= 154 | github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= 155 | go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= 156 | go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 157 | go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= 158 | go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= 159 | golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= 160 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 161 | golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= 162 | golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= 163 | golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 164 | golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 165 | golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 166 | golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 167 | golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 168 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 169 | golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 170 | golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 171 | golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= 172 | golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 173 | golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 174 | golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 175 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 176 | golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 177 | golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 178 | golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 179 | golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 180 | golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 181 | golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 182 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 183 | golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 184 | golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 185 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 186 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 187 | golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= 188 | golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 189 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 190 | golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 191 | golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 192 | golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 193 | golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 194 | golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= 195 | google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= 196 | google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= 197 | google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= 198 | google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= 199 | gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= 200 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 201 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 202 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 203 | gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= 204 | gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= 205 | gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= 206 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= 207 | gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= 208 | gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 209 | gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 210 | gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= 211 | gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 212 | gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E= 213 | gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= 214 | honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= 215 | k8s.io/apimachinery v0.17.3 h1:f+uZV6rm4/tHE7xXgLyToprg6xWairaClGVkm2t8omg= 216 | k8s.io/apimachinery v0.17.3/go.mod h1:gxLnyZcGNdZTCLnq3fgzyg2A5BVCHTNDFrw8AmuJ+0g= 217 | k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0= 218 | k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk= 219 | k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= 220 | k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I= 221 | k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E= 222 | sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= 223 | sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o= 224 | -------------------------------------------------------------------------------- /golangci.yml: -------------------------------------------------------------------------------- 1 | run: 2 | deadline: 2m 3 | 4 | linters: 5 | disable-all: true 6 | enable: 7 | - gofmt 8 | - goimports 9 | - golint 10 | - gosimple 11 | - ineffassign 12 | - misspell 13 | - govet 14 | -------------------------------------------------------------------------------- /internal/command/args.go: -------------------------------------------------------------------------------- 1 | package command 2 | 3 | import ( 4 | "github.com/docker/github-actions/internal/options" 5 | ) 6 | 7 | // LoginArgs converts login options into the cli arguments used to call `docker login` 8 | func LoginArgs(o options.Login, registry string) []string { 9 | args := []string{"login", "--username", o.Username, "--password", o.Password} 10 | if registry != "" { 11 | args = append(args, registry) 12 | } 13 | return args 14 | } 15 | 16 | // BuildArgs converts build options into the cli arguments used to call `docker build` 17 | func BuildArgs(o options.Build, github options.GitHub, tags []string) []string { 18 | args := []string{"build", "--progress", "plain"} 19 | 20 | for _, tag := range tags { 21 | args = append(args, "-t", tag) 22 | } 23 | 24 | for _, label := range options.GetLabels(o, github) { 25 | args = append(args, "--label", label) 26 | } 27 | 28 | if o.Dockerfile != "" { 29 | args = append(args, "--file", o.Dockerfile) 30 | } 31 | 32 | if o.Target != "" { 33 | args = append(args, "--target", o.Target) 34 | } 35 | 36 | if o.AlwaysPull { 37 | args = append(args, "--pull") 38 | } 39 | 40 | for _, cacheFrom := range o.CacheFroms { 41 | args = append(args, "--cache-from", cacheFrom) 42 | } 43 | 44 | for _, buildArg := range o.BuildArgs { 45 | args = append(args, "--build-arg", buildArg) 46 | } 47 | 48 | return append(args, o.Path) 49 | } 50 | 51 | // PushArgs converts tags into the cli arguments used to call `docker push` 52 | func PushArgs(tag string) []string { 53 | return []string{"push", tag} 54 | } 55 | -------------------------------------------------------------------------------- /internal/command/args_test.go: -------------------------------------------------------------------------------- 1 | package command 2 | 3 | import ( 4 | "testing" 5 | 6 | "github.com/docker/github-actions/internal/options" 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestLoginArgs(t *testing.T) { 11 | expected := []string{"login", "--username", "username", "--password", "password"} 12 | o := options.Login{ 13 | Username: "username", 14 | Password: "password", 15 | } 16 | args := LoginArgs(o, "") 17 | 18 | assert.DeepEqual(t, expected, args) 19 | 20 | args = LoginArgs(o, "registry") 21 | expected = append(expected, "registry") 22 | assert.DeepEqual(t, expected, args) 23 | } 24 | 25 | func TestBuildArgs(t *testing.T) { 26 | testCases := []struct { 27 | name string 28 | build options.Build 29 | tags []string 30 | expected []string 31 | }{ 32 | { 33 | name: "basic", 34 | build: options.Build{Path: "path"}, 35 | expected: []string{"build", "--progress", "plain", "path"}, 36 | }, 37 | { 38 | name: "with-dockerfile", 39 | build: options.Build{Path: ".", Dockerfile: "dockerfile"}, 40 | expected: []string{"build", "--progress", "plain", "--file", "dockerfile", "."}, 41 | }, 42 | { 43 | name: "with-tags", 44 | build: options.Build{Path: "."}, 45 | tags: []string{"tag1", "tag2"}, 46 | expected: []string{"build", "--progress", "plain", "-t", "tag1", "-t", "tag2", "."}, 47 | }, 48 | { 49 | name: "with-static-labels", 50 | build: options.Build{ 51 | Path: ".", 52 | Labels: []string{"label1", "label2"}, 53 | }, 54 | expected: []string{"build", "--progress", "plain", "--label", "label1", "--label", "label2", "."}, 55 | }, 56 | { 57 | name: "with-target", 58 | build: options.Build{ 59 | Path: ".", 60 | Target: "target", 61 | }, 62 | expected: []string{"build", "--progress", "plain", "--target", "target", "."}, 63 | }, 64 | { 65 | name: "with-always-pull", 66 | build: options.Build{ 67 | Path: ".", 68 | AlwaysPull: true, 69 | }, 70 | expected: []string{"build", "--progress", "plain", "--pull", "."}, 71 | }, 72 | { 73 | name: "with-build-args", 74 | build: options.Build{ 75 | Path: ".", 76 | BuildArgs: []string{"build-arg-1", "build-arg-2"}, 77 | }, 78 | expected: []string{"build", "--progress", "plain", "--build-arg", "build-arg-1", "--build-arg", "build-arg-2", "."}, 79 | }, 80 | { 81 | name: "with-cache-from", 82 | build: options.Build{ 83 | Path: ".", 84 | CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, 85 | }, 86 | expected: []string{"build", "--progress", "plain", "--cache-from", "foo/bar-1", "--cache-from", "foo/bar-2", "."}, 87 | }, 88 | } 89 | for _, tc := range testCases { 90 | tc := tc 91 | t.Run(tc.name, func(t *testing.T) { 92 | args := BuildArgs(tc.build, options.GitHub{}, tc.tags) 93 | assert.DeepEqual(t, tc.expected, args) 94 | }) 95 | } 96 | } 97 | 98 | func TestPushArgs(t *testing.T) { 99 | args := PushArgs("tag1") 100 | assert.DeepEqual(t, []string{"push", "tag1"}, args) 101 | } 102 | -------------------------------------------------------------------------------- /internal/command/runner.go: -------------------------------------------------------------------------------- 1 | package command 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "os/exec" 7 | 8 | "github.com/docker/github-actions/internal/options" 9 | ) 10 | 11 | // Runner executes standard commands 12 | type Runner interface { 13 | // Run executes the given command with arguments 14 | Run(name string, args ...string) error 15 | } 16 | 17 | type execRunner struct{} 18 | 19 | // NewRunner returns a new Runner with the stdout and stderr defaulting to os 20 | func NewRunner() Runner { 21 | return execRunner{} 22 | } 23 | 24 | // Run executes the given command with arguments using exec.Command 25 | func (runner execRunner) Run(name string, args ...string) error { 26 | cmd := exec.Command(name, args...) 27 | cmd.Stdout = os.Stdout 28 | cmd.Stderr = os.Stderr 29 | return cmd.Run() 30 | } 31 | 32 | // RunLogin runs a docker login 33 | func RunLogin(cmd Runner, opt options.Login, registry string) error { 34 | fmt.Println("Logging in to registry", registry) 35 | args := LoginArgs(opt, registry) 36 | return cmd.Run("docker", args...) 37 | } 38 | 39 | // RunBuild runs a docker build and tags the resulting image 40 | func RunBuild(cmd Runner, opt options.Build, github options.GitHub, tags []string) error { 41 | fmt.Println("Building image", tags) 42 | args := BuildArgs(opt, github, tags) 43 | return cmd.Run("docker", args...) 44 | } 45 | 46 | // RunPush runs a docker push for each tag 47 | func RunPush(cmd Runner, tags []string) error { 48 | fmt.Println("Pushing image", tags) 49 | for _, tag := range tags { 50 | args := PushArgs(tag) 51 | if err := cmd.Run("docker", args...); err != nil { 52 | return err 53 | } 54 | } 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /internal/options/build.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | "time" 7 | 8 | "github.com/caarlos0/env/v6" 9 | ) 10 | 11 | const opencontainersLabelPrefix = "org.opencontainers.image" 12 | 13 | // Build contains the parsed build action environment variables 14 | type Build struct { 15 | Path string `env:"INPUT_PATH"` 16 | Dockerfile string `env:"INPUT_DOCKERFILE"` 17 | AddGitLabels bool `env:"INPUT_ADD_GIT_LABELS"` 18 | Target string `env:"INPUT_TARGET"` 19 | AlwaysPull bool `env:"INPUT_ALWAYS_PULL"` 20 | CacheFroms []string 21 | BuildArgs []string 22 | Labels []string 23 | } 24 | 25 | // GetBuildOptions gets the login action environment variables 26 | func GetBuildOptions() (Build, error) { 27 | var build Build 28 | if err := env.Parse(&build); err != nil { 29 | return build, err 30 | } 31 | 32 | if cacheFroms := os.Getenv("INPUT_CACHE_FROMS"); cacheFroms != "" { 33 | build.CacheFroms = strings.Split(cacheFroms, ",") 34 | } 35 | 36 | if buildArgs := os.Getenv("INPUT_BUILD_ARGS"); buildArgs != "" { 37 | build.BuildArgs = strings.Split(buildArgs, ",") 38 | } 39 | 40 | if labels := os.Getenv("INPUT_LABELS"); labels != "" { 41 | build.Labels = strings.Split(labels, ",") 42 | } 43 | 44 | return build, nil 45 | } 46 | 47 | // GetLabels gets a list of all labels to build the image with including automatic labels created from github vars when AddGitLabels is true 48 | func GetLabels(build Build, github GitHub) []string { 49 | labels := []string{} 50 | if build.Labels != nil { 51 | labels = build.Labels 52 | } 53 | 54 | if !build.AddGitLabels { 55 | return labels 56 | } 57 | 58 | if github.Repository != "" { 59 | labels = append(labels, opencontainersLabelPrefix+".source=https://github.com/"+github.Repository) 60 | } 61 | 62 | if github.Sha != "" { 63 | labels = append(labels, opencontainersLabelPrefix+".revision="+github.Sha) 64 | 65 | } 66 | 67 | createdTime := time.Now().UTC().Format(time.RFC3339) 68 | labels = append(labels, opencontainersLabelPrefix+".created="+createdTime) 69 | 70 | return labels 71 | } 72 | -------------------------------------------------------------------------------- /internal/options/build_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | "testing" 7 | "time" 8 | 9 | "gotest.tools/v3/assert" 10 | ) 11 | 12 | func TestGetBuildOptions(t *testing.T) { 13 | _ = os.Setenv("INPUT_PATH", "path") 14 | _ = os.Setenv("INPUT_DOCKERFILE", "dockerfile") 15 | _ = os.Setenv("INPUT_CACHE_FROMS", "foo/bar-1,foo/bar-2") 16 | _ = os.Setenv("INPUT_REPOSITORY", "repository") 17 | _ = os.Setenv("INPUT_BUILD_ARGS", "buildarg1=b1,buildarg2=b2") 18 | _ = os.Setenv("INPUT_LABELS", "label1=l1,label2=l2") 19 | _ = os.Setenv("INPUT_ADD_GIT_LABELS", "false") 20 | _ = os.Setenv("INPUT_TARGET", "target") 21 | _ = os.Setenv("INPUT_ALWAYS_PULL", "true") 22 | 23 | o, err := GetBuildOptions() 24 | 25 | assert.NilError(t, err) 26 | assert.DeepEqual(t, Build{ 27 | Path: "path", 28 | Dockerfile: "dockerfile", 29 | Target: "target", 30 | AlwaysPull: true, 31 | BuildArgs: []string{"buildarg1=b1", "buildarg2=b2"}, 32 | Labels: []string{"label1=l1", "label2=l2"}, 33 | CacheFroms: []string{"foo/bar-1", "foo/bar-2"}, 34 | }, o) 35 | } 36 | 37 | func TestGetLabels(t *testing.T) { 38 | expected := []string{"label1", "label2"} 39 | labels := GetLabels(Build{Labels: expected}, GitHub{}) 40 | assert.DeepEqual(t, expected, labels) 41 | } 42 | 43 | func TestGetLabelsWithGit(t *testing.T) { 44 | labels := GetLabels( 45 | Build{ 46 | Labels: []string{"label1", "label2"}, 47 | AddGitLabels: true, 48 | }, 49 | GitHub{ 50 | Repository: "myrepository", 51 | Sha: "mysha", 52 | }) 53 | 54 | assert.Equal(t, 5, len(labels)) 55 | assert.Equal(t, "label1", labels[0]) 56 | assert.Equal(t, "label2", labels[1]) 57 | assert.Equal(t, "org.opencontainers.image.source=https://github.com/myrepository", labels[2]) 58 | assert.Equal(t, "org.opencontainers.image.revision=mysha", labels[3]) 59 | 60 | timeLabel := strings.SplitN(labels[4], "=", 2) 61 | assert.Equal(t, "org.opencontainers.image.created", timeLabel[0]) 62 | labelTime, err := time.Parse(time.RFC3339, timeLabel[1]) 63 | assert.NilError(t, err) 64 | assert.Assert(t, time.Now().After(labelTime)) 65 | } 66 | -------------------------------------------------------------------------------- /internal/options/github.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "strings" 6 | 7 | "github.com/caarlos0/env/v6" 8 | ) 9 | 10 | // GitReferenceType is the type of the git ref 11 | type GitReferenceType int 12 | 13 | // Get reference types 14 | const ( 15 | GitRefUnknown GitReferenceType = iota 16 | GitRefHead 17 | GitRefPullRequest 18 | GitRefTag 19 | ) 20 | 21 | // GitReference contains the type and name of the git ref 22 | type GitReference struct { 23 | Type GitReferenceType 24 | Name string 25 | } 26 | 27 | func parseGitRef(ref string) GitReference { 28 | if split := strings.SplitN(ref, "/", 3); len(split) == 3 { 29 | name := split[2] 30 | switch split[1] { 31 | case "heads": 32 | return GitReference{GitRefHead, name} 33 | case "pull": 34 | return GitReference{GitRefPullRequest, name} 35 | case "tags": 36 | return GitReference{GitRefTag, name} 37 | } 38 | } 39 | return GitReference{GitRefUnknown, ""} 40 | } 41 | 42 | // GitHub contains the parsed common github actions environment variables 43 | // See https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables 44 | type GitHub struct { 45 | RunInActions bool `env:"GITHUB_ACTIONS"` 46 | Workflow string `env:"GITHUB_WORKFLOW"` 47 | Action string `env:"GITHUB_ACTION"` 48 | Repository string `env:"GITHUB_REPOSITORY"` 49 | EventName string `env:"GITHUB_EVENT_NAME"` 50 | Sha string `env:"GITHUB_SHA"` 51 | Reference GitReference 52 | } 53 | 54 | // GetGitHubOptions gets the common github actions environment variables 55 | func GetGitHubOptions() (GitHub, error) { 56 | var github GitHub 57 | err := env.Parse(&github) 58 | if err != nil { 59 | return github, err 60 | } 61 | github.Reference = parseGitRef(os.Getenv("GITHUB_REF")) 62 | return github, nil 63 | } 64 | -------------------------------------------------------------------------------- /internal/options/github_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestGetGitHubOptions(t *testing.T) { 11 | _ = os.Setenv("GITHUB_ACTIONS", "true") 12 | _ = os.Setenv("GITHUB_WORKFLOW", "workflow") 13 | _ = os.Setenv("GITHUB_ACTION", "action") 14 | _ = os.Setenv("GITHUB_REPOSITORY", "repository") 15 | _ = os.Setenv("GITHUB_EVENT_NAME", "event-name") 16 | _ = os.Setenv("GITHUB_SHA", "sha") 17 | _ = os.Setenv("GITHUB_REF", "refs/heads/master") 18 | 19 | github, err := GetGitHubOptions() 20 | assert.NilError(t, err) 21 | assert.DeepEqual(t, GitHub{ 22 | RunInActions: true, 23 | Workflow: "workflow", 24 | Action: "action", 25 | Repository: "repository", 26 | EventName: "event-name", 27 | Sha: "sha", 28 | Reference: GitReference{ 29 | Type: GitRefHead, 30 | Name: "master", 31 | }, 32 | }, github) 33 | } 34 | 35 | func TestParseGitRef(t *testing.T) { 36 | testCases := []struct { 37 | name string 38 | ref string 39 | expectedType GitReferenceType 40 | expectedName string 41 | }{ 42 | { 43 | name: "master-branch", 44 | ref: "refs/heads/master", 45 | expectedType: GitRefHead, 46 | expectedName: "master", 47 | }, 48 | { 49 | name: "different-branch", 50 | ref: "refs/heads/different", 51 | expectedType: GitRefHead, 52 | expectedName: "different", 53 | }, 54 | { 55 | name: "pull-request", 56 | ref: "refs/pull/pr1", 57 | expectedType: GitRefPullRequest, 58 | expectedName: "pr1", 59 | }, 60 | { 61 | name: "tag", 62 | ref: "refs/tags/tag1", 63 | expectedType: GitRefTag, 64 | expectedName: "tag1", 65 | }, 66 | } 67 | for _, tc := range testCases { 68 | tc := tc 69 | t.Run(tc.name, func(t *testing.T) { 70 | ref := parseGitRef(tc.ref) 71 | assert.DeepEqual(t, GitReference{Type: tc.expectedType, Name: tc.expectedName}, ref) 72 | }) 73 | } 74 | } 75 | 76 | func TestGetGitHubOptionsNotInActions(t *testing.T) { 77 | _ = os.Unsetenv("GITHUB_ACTIONS") 78 | github, err := GetGitHubOptions() 79 | assert.NilError(t, err) 80 | assert.Equal(t, false, github.RunInActions) 81 | } 82 | -------------------------------------------------------------------------------- /internal/options/helper.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "strconv" 6 | ) 7 | 8 | func readBoolOption(key string) (bool, error) { 9 | o := os.Getenv(key) 10 | if o == "" { 11 | return false, nil 12 | } 13 | return strconv.ParseBool(o) 14 | } 15 | -------------------------------------------------------------------------------- /internal/options/login.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "errors" 5 | 6 | "github.com/caarlos0/env/v6" 7 | ) 8 | 9 | // Login contains the parsed login action environment variables 10 | type Login struct { 11 | Username string `env:"INPUT_USERNAME"` 12 | Password string `env:"INPUT_PASSWORD"` 13 | } 14 | 15 | var errLoginVarValidation = errors.New("both username and password must be set to login") 16 | 17 | // GetLoginOptions gets the login action environment variables 18 | func GetLoginOptions() (Login, error) { 19 | var login Login 20 | if err := env.Parse(&login); err != nil { 21 | return login, err 22 | } 23 | 24 | if login.Username != "" && login.Password == "" || 25 | login.Username == "" && login.Password != "" { 26 | return login, errLoginVarValidation 27 | } 28 | 29 | return login, nil 30 | } 31 | -------------------------------------------------------------------------------- /internal/options/login_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestGetLoginOptions(t *testing.T) { 11 | _ = os.Setenv("INPUT_USERNAME", "username") 12 | _ = os.Setenv("INPUT_PASSWORD", "password") 13 | 14 | o, err := GetLoginOptions() 15 | assert.NilError(t, err) 16 | assert.Equal(t, "username", o.Username) 17 | assert.Equal(t, "password", o.Password) 18 | } 19 | 20 | func TestLoginErrorNoPassword(t *testing.T) { 21 | _ = os.Setenv("INPUT_USERNAME", "username") 22 | _ = os.Unsetenv("INPUT_PASSWORD") 23 | 24 | _, err := GetLoginOptions() 25 | 26 | assert.Equal(t, err, errLoginVarValidation) 27 | } 28 | 29 | func TestLoginErrorNoUsername(t *testing.T) { 30 | _ = os.Setenv("INPUT_PASSWORD", "password") 31 | _ = os.Unsetenv("INPUT_USERNAME") 32 | 33 | _, err := GetLoginOptions() 34 | 35 | assert.Equal(t, err, errLoginVarValidation) 36 | } 37 | -------------------------------------------------------------------------------- /internal/options/push.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "errors" 5 | ) 6 | 7 | var errPushParse = errors.New("push input must be a valid boolean value") 8 | 9 | // ShouldPush returns true if the user has signalled a docker push should be performed 10 | func ShouldPush() (bool, error) { 11 | b, err := readBoolOption("INPUT_PUSH") 12 | if err != nil { 13 | return false, errPushParse 14 | } 15 | return b, nil 16 | } 17 | -------------------------------------------------------------------------------- /internal/options/push_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestShouldPush(t *testing.T) { 11 | testCases := []struct { 12 | name string 13 | input string 14 | expected bool 15 | expectedErr error 16 | }{ 17 | { 18 | name: "invalid", 19 | input: "invalid", 20 | expectedErr: errPushParse, 21 | }, 22 | { 23 | name: "true", 24 | input: "true", 25 | expected: true, 26 | }, 27 | { 28 | name: "false", 29 | input: "false", 30 | }, 31 | } 32 | for _, tc := range testCases { 33 | tc := tc 34 | t.Run(tc.name, func(t *testing.T) { 35 | _ = os.Setenv("INPUT_PUSH", tc.input) 36 | defer os.Unsetenv("INPUT_PUSH") 37 | should, err := ShouldPush() 38 | assert.Equal(t, tc.expectedErr, err) 39 | assert.Equal(t, tc.expected, should) 40 | }) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /internal/options/registry.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import "os" 4 | 5 | // GetRegistry gets the registry server from the github actions environment variables 6 | func GetRegistry() string { 7 | return os.Getenv("INPUT_REGISTRY") 8 | } 9 | -------------------------------------------------------------------------------- /internal/options/registry_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "os" 5 | "testing" 6 | 7 | "gotest.tools/v3/assert" 8 | ) 9 | 10 | func TestGetRegistry(t *testing.T) { 11 | _ = os.Unsetenv("INPUT_REGISTRY") 12 | assert.Equal(t, "", GetRegistry()) 13 | 14 | defer os.Unsetenv("INPUT_REGISTRY") 15 | _ = os.Setenv("INPUT_REGISTRY", "registry") 16 | assert.Equal(t, "registry", GetRegistry()) 17 | } 18 | -------------------------------------------------------------------------------- /internal/options/tag.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "os" 7 | "strings" 8 | ) 9 | 10 | var ( 11 | errTagWithRefParse = errors.New("tag_with_ref input must be a valid boolean value") 12 | errTagWithShaParse = errors.New("tag_with_sha input must be a valid boolean value") 13 | ) 14 | 15 | func tagWithRef() (bool, error) { 16 | b, err := readBoolOption("INPUT_TAG_WITH_REF") 17 | if err != nil { 18 | return false, errTagWithRefParse 19 | } 20 | return b, nil 21 | } 22 | 23 | func tagWithSha() (bool, error) { 24 | b, err := readBoolOption("INPUT_TAG_WITH_SHA") 25 | if err != nil { 26 | return false, errTagWithShaParse 27 | } 28 | return b, nil 29 | } 30 | 31 | func dockerRepo(github GitHub) string { 32 | if repo := os.Getenv("INPUT_REPOSITORY"); repo != "" { 33 | return repo 34 | } 35 | return strings.ToLower(github.Repository) 36 | } 37 | 38 | func staticTags() []string { 39 | if inputTags := os.Getenv("INPUT_TAGS"); inputTags != "" { 40 | return strings.Split(inputTags, ",") 41 | } 42 | return nil 43 | } 44 | 45 | func toFullTag(registry, repo, tag string) string { 46 | tag = strings.TrimSpace(tag) 47 | if registry != "" { 48 | return fmt.Sprintf("%s/%s:%s", registry, repo, tag) 49 | } 50 | return fmt.Sprintf("%s:%s", repo, tag) 51 | } 52 | 53 | // GetTags gets a list of all tags for including automatic tags from github vars when enabled along with the registry and repository 54 | func GetTags(registry string, github GitHub) ([]string, error) { 55 | repo := dockerRepo(github) 56 | var tags []string 57 | for _, t := range staticTags() { 58 | tags = append(tags, toFullTag(registry, repo, t)) 59 | } 60 | if withRef, err := tagWithRef(); err != nil { 61 | return nil, err 62 | } else if withRef { 63 | switch github.Reference.Type { 64 | case GitRefHead: 65 | if github.Reference.Name == "master" { 66 | tags = append(tags, toFullTag(registry, repo, "latest")) 67 | } else { 68 | tags = appendGitRefTag(tags, registry, repo, github.Reference.Name) 69 | } 70 | case GitRefPullRequest: 71 | tags = appendGitRefTag(tags, registry, repo, fmt.Sprintf("pr-%s", github.Reference.Name)) 72 | 73 | case GitRefTag: 74 | tags = appendGitRefTag(tags, registry, repo, github.Reference.Name) 75 | } 76 | } 77 | if withSha, err := tagWithSha(); err != nil { 78 | return nil, err 79 | } else if withSha { 80 | tags = appendShortGitShaTag(tags, github, registry, repo) 81 | } 82 | return tags, nil 83 | } 84 | 85 | func appendShortGitShaTag(tags []string, github GitHub, registry, repo string) []string { 86 | if len(github.Sha) >= 7 { 87 | tag := fmt.Sprintf("sha-%s", github.Sha[0:7]) 88 | return append(tags, toFullTag(registry, repo, tag)) 89 | } 90 | return tags 91 | } 92 | 93 | func appendGitRefTag(tags []string, registry, repo, refName string) []string { 94 | t := strings.ReplaceAll(refName, "/", "-") 95 | return append(tags, toFullTag(registry, repo, t)) 96 | } 97 | -------------------------------------------------------------------------------- /internal/options/tag_test.go: -------------------------------------------------------------------------------- 1 | package options 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | "testing" 7 | 8 | "gotest.tools/v3/assert" 9 | ) 10 | 11 | func TestGetTags(t *testing.T) { 12 | testCases := []struct { 13 | name string 14 | tagWithRef bool 15 | tagWithSha bool 16 | tags string 17 | ref GitReference 18 | registry string 19 | expected []string 20 | sha string 21 | }{ 22 | { 23 | name: "no-standard-tags", 24 | tags: "tag1,tag2", 25 | expected: []string{"my/repo:tag1", "my/repo:tag2"}, 26 | ref: GitReference{GitRefHead, "master"}, 27 | }, 28 | { 29 | name: "with-registry", 30 | tags: "tag1,tag2", 31 | expected: []string{"registry/my/repo:tag1", "registry/my/repo:tag2"}, 32 | registry: "registry", 33 | ref: GitReference{GitRefHead, "master"}, 34 | }, 35 | { 36 | name: "unknown-ref-type", 37 | tags: "tag1,tag2", 38 | expected: []string{"my/repo:tag1", "my/repo:tag2"}, 39 | tagWithRef: true, 40 | ref: GitReference{GitRefUnknown, "master"}, 41 | }, 42 | { 43 | name: "master-branch", 44 | tagWithRef: true, 45 | tags: "tag1,tag2", 46 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:latest"}, 47 | ref: GitReference{GitRefHead, "master"}, 48 | }, 49 | { 50 | name: "different-branch", 51 | tagWithRef: true, 52 | tags: "tag1,tag2", 53 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:branch-name"}, 54 | ref: GitReference{GitRefHead, "branch-name"}, 55 | }, 56 | { 57 | name: "pull-request", 58 | tagWithRef: true, 59 | tags: "tag1,tag2", 60 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:pr-name"}, 61 | ref: GitReference{GitRefPullRequest, "name"}, 62 | }, 63 | { 64 | name: "tag", 65 | tagWithRef: true, 66 | tags: "tag1,tag2", 67 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:v1.0"}, 68 | ref: GitReference{GitRefTag, "v1.0"}, 69 | }, 70 | { 71 | name: "master-branch-with-sha", 72 | tagWithRef: true, 73 | tags: "tag1,tag2", 74 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:latest"}, 75 | ref: GitReference{GitRefHead, "master"}, 76 | sha: "1234567890", 77 | }, 78 | { 79 | name: "pull-request-with-sha", 80 | tagWithRef: true, 81 | tags: "tag1,tag2", 82 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:pr-name"}, 83 | ref: GitReference{GitRefPullRequest, "name"}, 84 | sha: "1234567890", 85 | }, 86 | { 87 | name: "tag-with-sha", 88 | tagWithSha: true, 89 | tags: "tag1,tag2", 90 | expected: []string{"my/repo:tag1", "my/repo:tag2", "my/repo:sha-1234567"}, 91 | sha: "1234567890", 92 | }, 93 | } 94 | 95 | for _, tc := range testCases { 96 | tc := tc 97 | t.Run(tc.name, func(t *testing.T) { 98 | defer os.Unsetenv("INPUT_TAGS") 99 | defer os.Unsetenv("INPUT_REPOSITORY") 100 | defer os.Unsetenv("INPUT_TAG_WITH_REF") 101 | defer os.Unsetenv("INPUT_TAG_WITH_SHA") 102 | _ = os.Setenv("INPUT_TAGS", tc.tags) 103 | _ = os.Setenv("INPUT_REPOSITORY", "my/repo") 104 | _ = os.Setenv("INPUT_TAG_WITH_REF", fmt.Sprint(tc.tagWithRef)) 105 | _ = os.Setenv("INPUT_TAG_WITH_SHA", fmt.Sprint(tc.tagWithSha)) 106 | 107 | tags, err := GetTags( 108 | tc.registry, 109 | GitHub{Reference: tc.ref, Sha: tc.sha}, 110 | ) 111 | assert.NilError(t, err) 112 | assert.DeepEqual(t, tc.expected, tags) 113 | }) 114 | } 115 | } 116 | 117 | func TestGetTagsWithGitHubRepo(t *testing.T) { 118 | defer os.Unsetenv("INPUT_TAGS") 119 | _ = os.Setenv("INPUT_TAGS", "tag1") 120 | 121 | github := GitHub{Repository: "My/Repo"} 122 | tags, err := GetTags("", github) 123 | assert.NilError(t, err) 124 | assert.DeepEqual(t, []string{"my/repo:tag1"}, tags) 125 | } 126 | --------------------------------------------------------------------------------