Skip to content

Commit 809eacc

Browse files
author
rgaudin
authored
Merge pull request #1 from openzim/builx
Added platform support
2 parents 70b6e59 + 7205a95 commit 809eacc

14 files changed

Lines changed: 546 additions & 320 deletions

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
- name: Install dependencies
1616
run: python -m pip install -U pytest black
1717
- name: Black
18-
run: black -c compute_tags.py build_push.py
18+
run: black --check .
1919
- name: Tests
2020
run: pytest tests.py
2121

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# v4
2+
3+
- added support for any registries (still defaults to docker.io + ghcr.io)
4+
- replaced `dockerhub-*` and `ghcr-*` inputs with more flexible `credentials` one
5+
- renamed `image-path` to `image-name`
6+
- added `platforms` to support multiarch using `buildx`.
7+
- refactored and simplified action and scripts
8+
- now internally using two main info:
9+
- `DOCKER_TAG` with the version-only
10+
- `DOCKER_TAG_LATEST` `true` or `false`.
11+
12+
# v3
13+
14+
- added support for build-args
15+
116
# v2
217

318
- Fixed tag applied to images on tag event while having not set any tag-pattern

README.md

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,27 @@ On ghcr.io, as for Docker Hub, first part of image name is the *user* owning the
1515

1616
## Usage
1717

18+
### Minimal
19+
20+
```yaml
21+
jobs:
22+
build-and-push:
23+
name: Deploy Docker Image
24+
runs-on: ubuntu-20.04
25+
steps:
26+
- uses: actions/checkout@v2
27+
- name: Build and push
28+
uses: openzim/docker-publish-action@v4
29+
with:
30+
image-name: openzim/zimit
31+
DOCKERIO_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
32+
DOCKERIO_TOKEN=${{ secrets.DOCKERHUB_PASSWORD }}
33+
GHCR_IO_USERNAME=${{ secrets.GHCR_USERNAME }}
34+
GHCR_IO_TOKEN=${{ secrets.GHCR_TOKEN }}
35+
on-master: latest
36+
```
37+
38+
### Complete
1839
1940
```yaml
2041
name: Docker
@@ -33,36 +54,42 @@ jobs:
3354
steps:
3455
- uses: actions/checkout@v2
3556
- name: Build and push
36-
uses: openzim/docker-publish-action@v1
57+
uses: openzim/docker-publish-action@v4
3758
with:
38-
image-path: openzim/zimit
59+
image-name: openzim/zimit
60+
registries: |
61+
docker.io
62+
gcr.io
63+
credentials: |
64+
DOCKERIO_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}
65+
DOCKERIO_TOKEN=${{ secrets.DOCKERHUB_PASSWORD }}
66+
GCR_IO_USERNAME=${{ secrets.GOOGLE_USERNAME }}
67+
GCR_IO_TOKEN=${{ secrets.GOOGLE_TOKEN }}
68+
context: sub-folder
3969
on-master: dev
4070
tag-pattern: /^v*([0-9.]+)$/
4171
latest-on-tag: true
4272
restrict-to: openzim/zimit
43-
hub-username: ${{ secrets.DOCKERHUB_USERNAME }}
44-
hub-password: ${{ secrets.DOCKERHUB_PASSWORD }}
45-
ghcr-username: ${{ secrets.GHCR_USERNAME }}
46-
ghcr-token: ${{ secrets.GHCR_TOKEN }}
4773
build-args:
4874
VERSION={version}
49-
ARCH=amd64
5075
```
5176
5277
**Note**: th top-part `on` is just a filter on running that workflow. You can omit it but it's safer to not run it on refs that you know won't trigger anything. See [documentation](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#on).
5378

5479
| Input | Usage |
5580
| :--- | :--- |
56-
| `image-path`<font color=red>\*</font> | **Name of your image on the registry** (without the version part).<br />Ex.: `openzim/zimit` would refer to [this image](https://hub.docker.com/r/openzim/zimit).<br />The same name is pushed on **both registries**. |
57-
| `hub-username`<font color=red>\*</font> and `hub-password`<font color=red>\*</font> | **Docker Hub user credentials to push images with** |
58-
| `ghcr-username`<font color=red>\*</font> and `ghcr-token`<font color=red>\*</font> | **Github user credentials to push images with**<br />Token is a [PAT](https://github.com/settings/tokens) with `repo, workflow, write:packages` permissions.|
59-
| `context` | **Path in the repository to use as build context**<br />Relative to repository root. Defaults to `.`. Ex: `dnscache` or `workers/slave`. |
60-
| `dockerfile` | **Path to the Dockerfile recipe, relative to context**<br />Defaults to `Dockerfile`. Use `../` syntax if dockerfile is outside context. |
81+
| `image-name`<font color=red>\*</font> | **Name of your image on the registry** (without the version part).<br />Ex.: `openzim/zimit` would refer to [this image](https://hub.docker.com/r/openzim/zimit).<br />The same name is pushed to **all registries**. |
82+
| `registries` | **List of registries to push images to** (domain name only).<br />Ex.: `docker.io` for Docker Hub, `ghcr.io`, `gcr.io`, etc.<br />Defaults to `docker.io ghcr.io`. |
83+
| `credentials`<font color=red>\*</font> | **List of credentials for all registries**<br />Use the `REGISTRY_USERNAME=xxx` and `REGISTRY_TOKEN=xxx` formats to specify.<br />`REGISTRY` refers to the uppercase registry domain name without `.`.<br />Ex: `GHCRIO_USERNAME=xxx` for `ghcr.io`.<br />_Notes_: Github token is a [PAT](https://github.com/settings/tokens) with `repo, workflow, write:packages` permissions.<br />Docker hub token is account password.|
84+
| `context` | **Path in the repository to use as build context**<br />Relative to repository root. Ex: `dnscache` or `workers/slave`.<br />Defaults to `.`. |
85+
| `dockerfile` | **Path to the Dockerfile recipe, relative to context**<br />Use `../` syntax if dockerfile is outside context.<br />Defaults to `Dockerfile`. |
86+
| `build-args` | **Arguments for `docker build --build-arg`**<br />Special value `{version}` will be replaced with the tag to set.<br />Use the `name=value` format and separate each by a space or new line.|
87+
| `platforms` | **List of platforms to build-for**.<br />Ex.: `linux/armv/v7 linux/amd64`.<br />Defaults to `linux/amd64`. |
6188
| `on-master` | **Tag to apply for every commit on default branch**.<br />Omit it if you don't want to push an image for non-tagged commits.<br />Only applies to commits on your default branch (`master` or `main`) |
6289
| `tag-pattern` | **Regular expression to match tags with**.<br />Only git tags matching this regexp will trigger a build+push to the corresponding docker tag.<br />If not specifying a group, whole git tag is used as is on docker. |
6390
| `latest-on-tag` | **Whether to push to docker tag `:latest` on every matched tag** (see `tag-pattern`)<br />Value must be `true` or `false`. Defaults to `false`. |
6491
| `restrict-to` | **Don't push if action is run for a different repository**<br />Specify as `{owner}/{repository}`. |
65-
| `build-args` | **Arguments for `docker build --build-arg`**<br />Special value `{version}` will be replaced with the tag to set.<br />Use the `name=value` format and separate each by a space or new line.|
92+
6693

6794

6895
⚠️ After your initial run creating your image, you need to manually **make it public** via Github's UI (see packages) if you intend to pull images without authenticating.

action.yml

Lines changed: 46 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ branding:
66
color: green
77

88
inputs:
9-
image-path:
9+
image-name:
1010
description: target image path on both registries (ex. 'openzim/dnscache')
1111
required: true
12+
registries:
13+
description: list of registries to push to (defaults to docker.io ghcr.io)
14+
required: false
15+
default: docker.io ghcr.io
16+
credentials:
17+
description: list of credentials for each registry. Ex. DOCKERIO_USERNAME=xxx DOCKERIO_TOKEN=yyy GHCRIO_USERNAME=xxx
18+
required: true
1219
context:
1320
description: folder to use as context for the build (ex. '.' or 'dnscache')
1421
required: false
@@ -17,6 +24,13 @@ inputs:
1724
description: Dockerfile path (relative to context) if not 'Dockerfile'
1825
required: false
1926
default: Dockerfile
27+
build-args:
28+
description: optional key/value pairs to pass as build arguments. {version} replaced with found version/latest (if any)
29+
required: false
30+
platforms:
31+
description: specify platform to build for (one of linux/amd64, linux/arm64, linux/riscv64, linux/ppc64le, linux/s390x, linux/386, linux/arm/v7, linux/arm/v6, etc)
32+
required: false
33+
default: linux/amd64
2034
on-master:
2135
description: tag to use on master commits. (ex. 'latest' or 'dev') Leave out if not wanted
2236
required: false
@@ -30,70 +44,50 @@ inputs:
3044
restrict-to:
3145
description: repository path to limit this action to (ex. 'openzim/zimfarm') to prevent forks from triggering it.
3246
required: false
33-
hub-username:
34-
description: Docker Hub username to push image
35-
required: true
36-
hub-password:
37-
description: Docker Hub password to push image
38-
required: true
39-
ghcr-username:
40-
description: GHCR username to push image
41-
required: true
42-
ghcr-token:
43-
description: GHCR token to push image
44-
required: true
45-
build-args:
46-
description: optional key/value pairs to pass as build arguments. {version} replaced with found version/latest (if any)
47-
required: false
4847

4948
runs:
5049
using: composite
5150
steps:
52-
- run: echo "IMAGE_TAGS=" >> $GITHUB_ENV
51+
- name: check and store params
52+
run: python3 $GITHUB_ACTION_PATH/check_inputs.py
5353
shell: bash
54-
55-
- name: save build-args to env
56-
run: |
57-
import os
58-
import json
59-
build_args = dict([item.split("=") if "=" in item else (item, "") for item in os.getenv("BUILD_ARGS", "").split()])
60-
with open(os.getenv("GITHUB_ENV"), "a") as fh:
61-
fh.write("BUILD_ARGS={}\n".format(json.dumps(build_args)))
62-
shell: python
6354
env:
64-
BUILD_ARGS: ${{ inputs.build-args }}
65-
66-
- name: Compute Image Tags
67-
run: python3 $GITHUB_ACTION_PATH/compute_tags.py
68-
shell: bash
69-
env:
70-
IMAGE_PATH: ${{ inputs.image-path }}
55+
IMAGE_NAME: ${{ inputs.image-name }}
56+
REGISTRIES: ${{ inputs.registries }}
57+
CREDENTIALS: ${{ inputs.credentials }}
7158
CONTEXT: ${{ inputs.context }}
59+
DOCKERFILE: ${{ inputs.dockerfile }}
60+
BUILD_ARGS: ${{ inputs.build-args }}
61+
PLATFORMS: ${{ inputs.platforms }}
7262
ON_MASTER: ${{ inputs.on-master }}
7363
TAG_PATTERN: ${{ inputs.tag-pattern }}
7464
LATEST_ON_TAG: ${{ inputs.latest-on-tag }}
7565
RESTRICT_TO: ${{ inputs.restrict-to }}
7666
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
67+
DOCKER_BUILDX_VERSION: 0.5.1
7768

78-
- name: Verify Image tags
79-
run: |
80-
import os
81-
tags = [t for t in os.getenv("IMAGE_TAGS", "").strip().split(",") if t]
82-
if not tags:
83-
print("No expected tag to push to.")
84-
else:
85-
print("We'll build for and push to:")
86-
for tag in tags:
87-
print("- {}".format(tag))
88-
shell: python
69+
- name: find tag
70+
run: python3 $GITHUB_ACTION_PATH/find_tag.py
71+
shell: bash
72+
73+
- name: Display found tag
74+
run: python3 $GITHUB_ACTION_PATH/display_tag.py
75+
shell: bash
8976

90-
- name: Build and Push
91-
run: python3 $GITHUB_ACTION_PATH/build_push.py
77+
- name: docker install
78+
run: python3 $GITHUB_ACTION_PATH/docker_install.py
79+
shell: bash
80+
81+
- name: docker login
82+
run: python3 $GITHUB_ACTION_PATH/docker_login.py
9283
shell: bash
9384
env:
94-
CONTEXT: ${{ inputs.context }}
95-
DOCKERFILE: ${{ inputs.dockerfile }}
96-
DOCKERHUB_USERNAME: ${{ inputs.hub-username }}
97-
DOCKERHUB_PASSWORD: ${{ inputs.hub-password }}
98-
GHCR_USERNAME: ${{ inputs.ghcr-username }}
99-
GHCR_TOKEN: ${{ inputs.ghcr-token }}
85+
CREDENTIALS: ${{ inputs.credentials }}
86+
87+
- name: docker build-push
88+
run: python3 $GITHUB_ACTION_PATH/docker_build.py
89+
shell: bash
90+
91+
- name: docker logout
92+
run: python3 $GITHUB_ACTION_PATH/docker_logout.py
93+
shell: bash

build_push.py

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)