This repository was archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
DESKTOP-2412 Github action 1: Write first code to run the action #2
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
316b48b
Adding github and login args and command
zappy-shu d062807
Adding build opts and default tags/labels
zappy-shu 2f380ad
Removing run ID and number
zappy-shu 421f37e
Adding build command
zappy-shu 5605e2c
Add ability to override both dockerfile and path
zappy-shu 0f77e60
Add initial e2e framework
zappy-shu d9614cd
Create registry from Dockerfile for e2e
zappy-shu a090946
Add poll to e2e login
zappy-shu b39a5bf
Add e2e tests for build
zappy-shu b61c5d7
Extract tags from build options
zappy-shu 7c1edfc
Extract server from build and login options
zappy-shu 212300f
Add push command
zappy-shu f6482be
Build/lint/unit-test in one docker build
zappy-shu cf7a3c0
Add build-push command and tests
zappy-shu 8754d5a
try using buildkit
zappy-shu c6df8c6
Add short-sha to tags
zappy-shu 17373ac
Updating readme with env vars
zappy-shu 09a935f
Refactor command running
zappy-shu 8c0a723
Add push filter
zappy-shu 4cc816e
Split tags for sha and ref
zappy-shu 5c92bfd
Switching from urfave/cli to cobra
zappy-shu cb5ad12
Error is username or password set but not both
zappy-shu 6867dc1
Refactoring nits for PR
zappy-shu f929a47
Use hashicorp/go-multierror
zappy-shu 78d3747
Remove unrequired Getwd() from e2e tests
zappy-shu ba8eb48
Use cmd.Env to set env vars in e2e tests
zappy-shu 791388d
Update doc for INPUT_TARGET to match cli help
zappy-shu e856f73
Add git labels description in readme
zappy-shu 8049084
Rename server input to registry
zappy-shu 66d44b6
Return err when boolean inputs invalid
zappy-shu e93e32e
Only replace / when tagging with ref
zappy-shu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,143 @@ | ||
| # github-actions | ||
| 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 Actions | ||
| 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 Actions. | ||
|
|
||
| `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. | ||
|
|
||
| ## Commands | ||
|
|
||
| Commands can be called using `docker run docker/github-actions {command}` | ||
|
|
||
| ### login | ||
|
|
||
| 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. | ||
zappy-shu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| #### inputs | ||
|
|
||
| |Environment Variable|Required|Description| | ||
| |---|---|---| | ||
| |INPUT_USERNAME|yes|Username to login with| | ||
| |INPUT_PASSWORD|yes|Password to login with| | ||
| |INPUT_REGISTRY|no|Registry server to login to. Defaults to Docker Hub| | ||
|
|
||
| ### build | ||
|
|
||
| Builds and tags a docker image. | ||
|
|
||
| #### inputs | ||
|
|
||
| |Environment Variable|Required|Description| | ||
| |---|---|---| | ||
| |INPUT_PATH|yes|Path to build from| | ||
| |INPUT_DOCKERFILE|no|Path to Dockerfile| | ||
| |INPUT_ADD_GIT_LABELS|no|Adds git labels (see below)| | ||
| |INPUT_TARGET|no|Target build stage to build| | ||
| |INPUT_BUILD_ARGS|no|Comma-delimited list of build-args| | ||
| |INPUT_LABELS|no|Comma-delimited list of labels| | ||
|
|
||
| See the tagging section for information on tag inputs | ||
|
|
||
| ##### Git labels | ||
|
|
||
| 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: | ||
|
|
||
| |Label|Description| | ||
| |---|---| | ||
| |com.docker.github-actions-actor|The username of the user that kicked off this run of the actions (e.g. the user that did the git push)| | ||
| |com.docker.github-actions-sha|The full git sha of this commit| | ||
|
|
||
| ### push | ||
|
|
||
| Pushes a docker image. | ||
|
|
||
| #### inputs | ||
|
|
||
| See the tagging section for information on tag inputs | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually we should make these links
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. Will get round to it once the inputs and tags have been finalized |
||
|
|
||
|
|
||
| ### build-push | ||
|
|
||
| Builds, logs in, and pushes a docker image. | ||
|
|
||
| #### inputs | ||
|
|
||
| Same as the login and build commands with the addition of | ||
|
|
||
| |Environment Variable|Required|Description| | ||
| |---|---|---| | ||
| |INPUT_PUSH|no|Will push the image if true| | ||
|
|
||
|
|
||
| ## Tagging | ||
|
|
||
| Tagging of images can be set manually, left to `github-actions` to automate, or a combination of the both. | ||
|
|
||
| There are 4 input variables used for tagging | ||
|
|
||
| |Environment Variable|Required|Description| | ||
| |---|---|---| | ||
| |INPUT_REGISTRY|no|Registry server to tag with| | ||
| |INPUT_REPOSITORY|yes|Repository to tag with| | ||
| |INPUT_TAGS|no|Hard coded comma-delimited list of tags| | ||
| |INPUT_TAG_WITH_REF|no|If true then `github-actions` will add tags depending on the git ref automatically as described below| | ||
| |INPUT_TAG_WITH_SHA|no|If true then `github-actions` will add a tag in the form `sha-{git-short-sha}`| | ||
|
|
||
| If `INPUT_REGISTRY` is set then all tags are prefixed with `{INPUT_REGISTRY}/{INPUT_REPOSITORY}:`. | ||
| If not then all tags are prefixed with `{INPUT_REPOSITORY}:` | ||
|
|
||
| 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. | ||
|
|
||
| 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`. | ||
|
|
||
| If the reference is `refs/pull-requests/{pr}` then the tag `pr-{pr}` is added. | ||
|
|
||
| If the reference is `refs/tags/{tag-name}` then the tag `{tag-name}` is added. | ||
|
|
||
| Any `/` in the auto tags are replaced with `-`. | ||
|
|
||
| For example if the environment variables are as follows: | ||
|
|
||
| |Variable|Value| | ||
| |---|---| | ||
| |INPUT_REGISTRY|| | ||
| |INPUT_REPOSITORY|myorg/myimage| | ||
| |INPUT_TAGS|foo,bar| | ||
| |INPUT_TAG_WITH_REF|true| | ||
| |GITHUB_REF|refs/tags/v0.1| | ||
|
|
||
| Then the image will be tagged with: | ||
| ``` | ||
| myorg/myimage:foo | ||
| myorg/myimage:bar | ||
| myorg/myimage:v0.1 | ||
| ``` | ||
|
|
||
| If the variables are as follows: | ||
|
|
||
| |Variable|Value| | ||
| |---|---| | ||
| |INPUT_REGISTRY|myregistry| | ||
| |INPUT_REPOSITORY|myorg/myimage| | ||
| |INPUT_TAGS|foo,bar| | ||
| |INPUT_TAG_WITH_REF|true| | ||
| |INPUT_TAG_WITH_SHA|true| | ||
| |GITHUB_REF|refs/heads/master| | ||
| |GITHUB_SHA|c6df8c68eb71799f9c9ab4a4a4650d6aabd7e415| | ||
|
|
||
| Then the image will be tagged with: | ||
| ``` | ||
| myregistry/myorg/myimage:foo | ||
| myregistry/myorg/myimage:bar | ||
| myregistry/myorg/myimage:lastest | ||
| myregistry/myorg/myimage:c6df8c6 | ||
| ``` | ||
|
|
||
| ## Building github-actions | ||
| 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`. | ||
|
|
||
| `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 | ||
|
|
||
| `make -f docker.Makefile TAG=foo` 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:foo | ||
|
|
||
| `make -f docker.Makefile image` will build the github-actions image without a tag and without running test or lint checking | ||
|
|
||
| `make -f docker.Makefile cli` will build the cli and copy it to `./bin/github-actions` | ||
|
|
||
| `make -f docker.Makefile test` will run the go tests | ||
| `make -f docker.Makefile test` will run the unit and e2e tests | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/docker/github-actions/internal/command" | ||
| "github.com/docker/github-actions/internal/options" | ||
| ) | ||
|
|
||
| func build(cmd command.Runner) error { | ||
| o, err := options.GetBuildOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| github, err := options.GetGitHubOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| tags, err := options.GetTags(options.GetRegistry(), github) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return command.RunBuild(cmd, o, github, tags) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/docker/github-actions/internal/command" | ||
| "github.com/docker/github-actions/internal/options" | ||
| ) | ||
|
|
||
| func buildPush(cmd command.Runner) error { | ||
| github, err := options.GetGitHubOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| registry := options.GetRegistry() | ||
| tags, err := options.GetTags(registry, github) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| build, err := options.GetBuildOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err = command.RunBuild(cmd, build, github, tags); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if shouldPush, err := options.ShouldPush(); err != nil { | ||
| return err | ||
| } else if shouldPush { | ||
| login, err := options.GetLoginOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if login.Username != "" && login.Password != "" { | ||
zappy-shu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err := command.RunLogin(cmd, login, registry); err != nil { | ||
| return err | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return command.RunPush(cmd, tags) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "github.com/docker/github-actions/internal/command" | ||
| "github.com/docker/github-actions/internal/options" | ||
| ) | ||
|
|
||
| func login(cmd command.Runner) error { | ||
| o, err := options.GetLoginOptions() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return command.RunLogin(cmd, o, options.GetRegistry()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.