|
1 | 1 | # github-actions |
2 | | -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 |
| 2 | +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. |
3 | 3 |
|
| 4 | +`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. |
| 5 | + |
| 6 | +## Commands |
| 7 | + |
| 8 | +Commands can be called using `docker run docker/github-actions {command}` |
| 9 | + |
| 10 | +### login |
| 11 | + |
| 12 | +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. |
| 13 | + |
| 14 | +#### inputs |
| 15 | + |
| 16 | +|Environment Variable|Required|Description| |
| 17 | +|---|---|---| |
| 18 | +|INPUT_USERNAME|yes|Username to login with| |
| 19 | +|INPUT_PASSWORD|yes|Password to login with| |
| 20 | +|INPUT_REGISTRY|no|Registry server to login to. Defaults to Docker Hub| |
| 21 | + |
| 22 | +### build |
| 23 | + |
| 24 | +Builds and tags a docker image. |
| 25 | + |
| 26 | +#### inputs |
| 27 | + |
| 28 | +|Environment Variable|Required|Description| |
| 29 | +|---|---|---| |
| 30 | +|INPUT_PATH|yes|Path to build from| |
| 31 | +|INPUT_DOCKERFILE|no|Path to Dockerfile| |
| 32 | +|INPUT_ADD_GIT_LABELS|no|Adds git labels (see below)| |
| 33 | +|INPUT_TARGET|no|Target build stage to build| |
| 34 | +|INPUT_BUILD_ARGS|no|Comma-delimited list of build-args| |
| 35 | +|INPUT_LABELS|no|Comma-delimited list of labels| |
| 36 | + |
| 37 | +See the tagging section for information on tag inputs |
| 38 | + |
| 39 | +##### Git labels |
| 40 | + |
| 41 | +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: |
| 42 | + |
| 43 | +|Label|Description| |
| 44 | +|---|---| |
| 45 | +|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)| |
| 46 | +|com.docker.github-actions-sha|The full git sha of this commit| |
| 47 | + |
| 48 | +### push |
| 49 | + |
| 50 | +Pushes a docker image. |
| 51 | + |
| 52 | +#### inputs |
| 53 | + |
| 54 | +See the tagging section for information on tag inputs |
| 55 | + |
| 56 | + |
| 57 | +### build-push |
| 58 | + |
| 59 | +Builds, logs in, and pushes a docker image. |
| 60 | + |
| 61 | +#### inputs |
| 62 | + |
| 63 | +Same as the login and build commands with the addition of |
| 64 | + |
| 65 | +|Environment Variable|Required|Description| |
| 66 | +|---|---|---| |
| 67 | +|INPUT_PUSH|no|Will push the image if true| |
| 68 | + |
| 69 | + |
| 70 | +## Tagging |
| 71 | + |
| 72 | +Tagging of images can be set manually, left to `github-actions` to automate, or a combination of the both. |
| 73 | + |
| 74 | +There are 4 input variables used for tagging |
| 75 | + |
| 76 | +|Environment Variable|Required|Description| |
| 77 | +|---|---|---| |
| 78 | +|INPUT_REGISTRY|no|Registry server to tag with| |
| 79 | +|INPUT_REPOSITORY|yes|Repository to tag with| |
| 80 | +|INPUT_TAGS|no|Hard coded comma-delimited list of tags| |
| 81 | +|INPUT_TAG_WITH_REF|no|If true then `github-actions` will add tags depending on the git ref automatically as described below| |
| 82 | +|INPUT_TAG_WITH_SHA|no|If true then `github-actions` will add a tag in the form `sha-{git-short-sha}`| |
| 83 | + |
| 84 | +If `INPUT_REGISTRY` is set then all tags are prefixed with `{INPUT_REGISTRY}/{INPUT_REPOSITORY}:`. |
| 85 | +If not then all tags are prefixed with `{INPUT_REPOSITORY}:` |
| 86 | + |
| 87 | +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. |
| 88 | + |
| 89 | +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`. |
| 90 | + |
| 91 | +If the reference is `refs/pull-requests/{pr}` then the tag `pr-{pr}` is added. |
| 92 | + |
| 93 | +If the reference is `refs/tags/{tag-name}` then the tag `{tag-name}` is added. |
| 94 | + |
| 95 | +Any `/` in the auto tags are replaced with `-`. |
| 96 | + |
| 97 | +For example if the environment variables are as follows: |
| 98 | + |
| 99 | +|Variable|Value| |
| 100 | +|---|---| |
| 101 | +|INPUT_REGISTRY|| |
| 102 | +|INPUT_REPOSITORY|myorg/myimage| |
| 103 | +|INPUT_TAGS|foo,bar| |
| 104 | +|INPUT_TAG_WITH_REF|true| |
| 105 | +|GITHUB_REF|refs/tags/v0.1| |
| 106 | + |
| 107 | +Then the image will be tagged with: |
| 108 | +``` |
| 109 | +myorg/myimage:foo |
| 110 | +myorg/myimage:bar |
| 111 | +myorg/myimage:v0.1 |
| 112 | +``` |
| 113 | + |
| 114 | +If the variables are as follows: |
| 115 | + |
| 116 | +|Variable|Value| |
| 117 | +|---|---| |
| 118 | +|INPUT_REGISTRY|myregistry| |
| 119 | +|INPUT_REPOSITORY|myorg/myimage| |
| 120 | +|INPUT_TAGS|foo,bar| |
| 121 | +|INPUT_TAG_WITH_REF|true| |
| 122 | +|INPUT_TAG_WITH_SHA|true| |
| 123 | +|GITHUB_REF|refs/heads/master| |
| 124 | +|GITHUB_SHA|c6df8c68eb71799f9c9ab4a4a4650d6aabd7e415| |
| 125 | + |
| 126 | +Then the image will be tagged with: |
| 127 | +``` |
| 128 | +myregistry/myorg/myimage:foo |
| 129 | +myregistry/myorg/myimage:bar |
| 130 | +myregistry/myorg/myimage:lastest |
| 131 | +myregistry/myorg/myimage:c6df8c6 |
| 132 | +``` |
4 | 133 |
|
5 | 134 | ## Building github-actions |
6 | 135 | 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`. |
7 | 136 |
|
8 | 137 | `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 |
9 | 138 |
|
10 | | -`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 |
11 | | - |
12 | 139 | `make -f docker.Makefile image` will build the github-actions image without a tag and without running test or lint checking |
13 | 140 |
|
14 | 141 | `make -f docker.Makefile cli` will build the cli and copy it to `./bin/github-actions` |
15 | 142 |
|
16 | | -`make -f docker.Makefile test` will run the go tests |
| 143 | +`make -f docker.Makefile test` will run the unit and e2e tests |
0 commit comments