Skip to content
This repository was archived by the owner on Nov 24, 2025. It is now read-only.

Commit 2a762b7

Browse files
authored
Merge pull request #129 from philips-software/add-documentation-on-automated-versions
Add example on major, minor, and patch releases.
2 parents 9037fe0 + d3c3c1e commit 2a762b7

1 file changed

Lines changed: 53 additions & 15 deletions

File tree

README.md

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
<div align="center">
22

3-
# GitHub Action for creating and publishing docker images
3+
# GitHub Action for creating and publishing docker images
44

55
[![Marketplace](https://img.shields.io/badge/GitHub-Marketplace-green.svg)](https://github.com/marketplace/actions/docker-build-and-publish) [![Release](https://img.shields.io/github/release/philips-software/docker-ci-scripts.svg)](https://github.com/philips-software/docker-ci-scripts/releases)
66

7-
This action will build a docker image from a given directory.
7+
This action will build a docker image from a given directory.
88
</div>
99

1010
- You can give a docker image multiple tags.
11-
- You can specify for which branch it should push to a docker registry ( `docker.io` by default ).
11+
- You can specify for which branch it should push to a docker registry ( `docker.io` by default ).
1212
- Each docker image contains information about the exact context in which the image is build.
1313
- When pushing to docker.io, the description is updated with the `readme.md` file.
1414
- If required, the image is signed with [cosign](https://github.com/sigstore/cosign).
15-
- If required, a provenance file is created according to the [SLSA.dev](https://slsa.dev) specifications.
16-
- If required, the provenance file is attached to the container.
15+
- If required, a provenance file is created according to the [SLSA.dev](https://slsa.dev) specifications.
16+
- If required, the provenance file is attached to the container.
1717
- If required, a SBOM file is created according to the [SPDX](https://spdx.dev) specifications. We're using [VMWare Tern](https://github.com/tern-tools/tern) for that. (very slow at the moment)
18-
- If required, the SBOM file is attached to the container.
18+
- If required, the SBOM file is attached to the container.
1919

2020
In every docker image two files are added to the build context:
2121
* `TAGS` - contains all tags associated with the image at time it was build.
@@ -69,26 +69,26 @@ Builds docker images and publish them on request
6969

7070
These variables can be set in the github repository secret vault.
7171

72-
### `DOCKER_USERNAME`
72+
### `DOCKER_USERNAME`
7373

7474
**Required** Docker username
7575

76-
### `DOCKER_PASSWORD`
76+
### `DOCKER_PASSWORD`
7777

7878
**Required** Docker password
7979

80-
### `DOCKER_REGISTRY`
80+
### `DOCKER_REGISTRY`
8181

8282
**Optional** Registry to push the docker image to. Defaults to Docker hub.
8383

84-
### `DOCKER_ORGANIZATION`
84+
### `DOCKER_ORGANIZATION`
8585

8686
**Required for Docker hub** Container will be pushed in this organization. Example: `philipssoftware`
8787
No need to put this in GitHub Secret vault. This will be public anyway.
8888

89-
### `GITHUB_ORGANIZATION`
89+
### `GITHUB_ORGANIZATION`
9090

91-
**Optional** Github organization. Defaults to DOCKER_ORGANIZATION. Example: `philips-software`
91+
**Optional** Github organization. Defaults to DOCKER_ORGANIZATION. Example: `philips-software`
9292
No need to put this in GitHub Secret vault. This will be public anyway.
9393

9494
### `COSIGN_PRIVATE_KEY`
@@ -276,7 +276,7 @@ You can inspect the provenance and decide on whether you want use the image.
276276
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
277277
DOCKER_REGISTRY: ghcr.io/organization-here
278278
GITHUB_ORGANIZATION: organization-here
279-
- name: Show SBOM
279+
- name: Show SBOM
280280
run: |
281281
cat ${{ steps.docker.outputs.sbom-file }}
282282
```
@@ -349,6 +349,44 @@ $ cosign verify-attestation --key cosign.pub jeroenknoops/test-image:latest | jq
349349
This is nice, because you can see the SBOM of the image, without downloading it!
350350
You can inspect the SBOM and decide on whether you want use the image.
351351

352+
#### Automatically create major minor and patch versions
353+
354+
Sometimes you want to automatically create major, minor and patch releases for certain tags in the repository.
355+
For example when you create a git tag: `v2.32.1` you might want to automatically create versions: `2`, `2.32`, and `2.32.1`.
356+
357+
This can be done with a small snippet:
358+
359+
```yaml
360+
- name: SplitTag
361+
if: startsWith(github.ref, 'refs/tags/v')
362+
run: |
363+
refIN=${GITHUB_REF##*/}
364+
arrIN=(${refIN//./ })
365+
echo "major=${arrIN[0]}" >> $GITHUB_ENV
366+
echo "minor=${arrIN[0]}.${arrIN[1]}" >> $GITHUB_ENV
367+
echo "patch=${arrIN[0]}.${arrIN[1]}.${arrIN[2]}" >> $GITHUB_ENV
368+
369+
- name: Set no tag
370+
if: startsWith(github.ref, 'refs/tags/v') == false
371+
run: |
372+
echo "major=" >> $GITHUB_ENV
373+
echo "minor=" >> $GITHUB_ENV
374+
echo "patch=" >> $GITHUB_ENV
375+
376+
- uses: philips-software/docker-ci-scripts@v4.2.0
377+
with:
378+
dockerfile: './docker/Dockerfile'
379+
image-name: 'node'
380+
tags: 'latest ${{ env.major }} ${{ env.minor }} ${{ env.patch }}'
381+
push-on-git-tag: 'true'
382+
env:
383+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
384+
DOCKER_PASSWORD: '${{ secrets.DOCKER_PASSWORD }}'
385+
DOCKER_ORGANIZATION: myDockerOrganization
386+
```
387+
388+
Thanks to [@daantimmer](https://github.com/daantimmer) to provide this snippet.
389+
352390
## Example projects
353391

354392
* [philips-software/docker-node](https://github.com/philips-software/docker-node)
@@ -361,7 +399,7 @@ You can inspect the SBOM and decide on whether you want use the image.
361399
## Breaking changes v3.0.0
362400

363401
The `docker build` command is now being called from the root of the project
364-
instead of the directory.
402+
instead of the directory.
365403

366404
This has impact when your project has these two things:
367405
- Directories with dockerfiles
@@ -370,7 +408,7 @@ This has impact when your project has these two things:
370408
You now need to change the path to include the directory.
371409

372410
Example:
373-
- `ADD /scripts/entrypoint.sh entrypoint.sh` becomes: `ADD /6/java/scripts/entrypoint.sh entrypoint`
411+
- `ADD /scripts/entrypoint.sh entrypoint.sh` becomes: `ADD /6/java/scripts/entrypoint.sh entrypoint`
374412

375413
## Contributors
376414

0 commit comments

Comments
 (0)