Skip to content

Commit ce6a652

Browse files
committed
Add more functionality and safety to build.sh
- Add --tag CLI flag to add the corresponding Git tag (useful to create releases without typos or copy&paste mistakes). Fails with error when a branch other than master is checked out, since releases should always be created on the master branch. - Pass --pull to "docker build" to ensure we always base our images on the latest base image. - Reject pushing images to Docker Registry if the corresponding Git tag already exists (i.e. image is officially released). Avoids overwriting released images by accident, but still allow overwriting (unreleased) images during development/testing phase.
1 parent 2304949 commit ce6a652

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,19 @@ Same purpose as `windowsservercore-ltsc2019-qt5.15.0-32bit`, but with Qt 5.15.2.
8989

9090
## Updating Images
9191

92+
**Important: On Linux, use the helper script `./build.sh` since it makes the
93+
procedure less error prone!**
94+
9295
1. Add/modify the Dockerfiles, update this README and commit all changes.
93-
2. Run `./build.sh <image-tag> <version> --push` to build and push the image.
94-
Make sure to pass a version number which does not yet exist on Docker Hub!
96+
2. Run `./build.sh <image-name> <version> --push` to build and push the image.
97+
Use the next unused version number, i.e. the previous image version plus one.
9598
Use just a single number as version identifier, e.g. `1`, `2`, `3`. Semantic
9699
versioning is not needed since CI always links to one specific version.
97-
3. Add and push a Git tag with the exact image tag (e.g. `ubuntu-18.04-1`).
100+
3. Test the new image by pushing the LibrePCB repository to trigger the CI.
101+
4. If everything was successful, merge the changes into `master`.
102+
5. On the `master` branch (merge commit checked out!), create the corresponding
103+
Git tag by running `./build.sh <image-name> <version> --tag` (can also be
104+
combined with `--push` to push the image again).
98105

99106

100107
## Using Images Locally

build.sh

+46-6
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,59 @@ set -eu -o pipefail
55

66
# Usage:
77
#
8-
# ./build.sh <tag> <version> [--push]
8+
# ./build.sh <name> <version> [--push] [--tag]
99
#
1010
# Example:
1111
#
1212
# ./build.sh ubuntu-18.04 2 --push
1313

14-
TAG="$1"
14+
NAME="$1"
1515
VERSION="$2"
16-
FLAG="${3-}"
16+
DO_PUSH=0
17+
DO_TAG=0
18+
for i in "$@"
19+
do
20+
case $i in
21+
--push)
22+
DO_PUSH=1
23+
shift
24+
;;
25+
--tag)
26+
DO_TAG=1
27+
shift
28+
;;
29+
esac
30+
done
1731

18-
docker build -t librepcb/librepcb-dev:$TAG-$VERSION $TAG
32+
echo "Build image $NAME-$VERSION..."
33+
docker build --pull -t librepcb/librepcb-dev:$NAME-$VERSION $NAME
1934

20-
if [ "$FLAG" = "--push" ]
35+
if [ "$DO_PUSH" == 1 ]
2136
then
22-
docker push librepcb/librepcb-dev:$TAG-$VERSION
37+
# Fail if the corresponding Git tag exists, since this means that the
38+
# image was already released and we must not overwrite released images.
39+
if git rev-parse "$NAME-$VERSION" >/dev/null 2>&1
40+
then
41+
echo "ERROR: This image is already released (Git tag exists)!"
42+
exit 1
43+
fi
44+
45+
echo "Push image $NAME-$VERSION..."
46+
docker push librepcb/librepcb-dev:$NAME-$VERSION
47+
fi
48+
49+
if [ "$DO_TAG" == 1 ]
50+
then
51+
# Fail if a branch other than master is checked out since we should create
52+
# releases only from the master branch.
53+
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
54+
if [[ "$BRANCH" != "master" ]]
55+
then
56+
echo "ERROR: Releases must be created on master branch, not $BRANCH!"
57+
exit 1
58+
fi
59+
60+
echo "Create Git tag $NAME-$VERSION..."
61+
git tag "$NAME-$VERSION"
62+
git push origin "$NAME-$VERSION"
2363
fi

0 commit comments

Comments
 (0)