Skip to content

Commit f525f3e

Browse files
committed
change to madebytimo/base as base image
1 parent f036442 commit f525f3e

File tree

12 files changed

+300
-145
lines changed

12 files changed

+300
-145
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
name: "build and release"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
8+
schedule:
9+
- cron: "00 01 * * *"
10+
workflow_dispatch:
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
- name: Create cache folder
21+
run: |
22+
sudo mkdir --parents /media/saved-cache
23+
sudo chown -R "$(whoami)" /media/saved-cache
24+
- name: Get cache
25+
uses: actions/cache/restore@v4
26+
with:
27+
path: /media/saved-cache
28+
key: docker-scripts-build-cache-${{ github.run_id }}
29+
restore-keys: docker-scripts-build-cache
30+
- name: Import cache
31+
run: |
32+
if (ls /media/saved-cache/*.tar.zst); then
33+
docker run --pull always --rm \
34+
--volume "/media/saved-cache:/media/saved-cache" \
35+
--volume \
36+
"docker-scripts-build-cache:/media/build-cache" \
37+
--workdir /media \
38+
madebytimo/scripts \
39+
compress.sh --decompress /media/saved-cache/*.tar.zst
40+
rm /media/saved-cache/*.tar.zst
41+
fi
42+
- name: Set secrets and variables
43+
run: |
44+
mkdir data-local
45+
echo "latest_version=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
46+
echo "version=$(cat Version.txt)" >> "$GITHUB_ENV"
47+
if [[ -n '${{ secrets.UNITY_LICENSE_FILE }}' ]]; then
48+
echo '${{ secrets.UNITY_LICENSE_FILE }}' > data-local/unity-license.ulf
49+
fi
50+
if [[ -n '${{ secrets.DOCKER_REGISTRY_USERNAME }}' ]]; then
51+
echo ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | \
52+
docker login --username ${{ secrets.DOCKER_REGISTRY_USERNAME }} \
53+
--password-stdin ${{ secrets.DOCKER_REGISTRY_URL }}
54+
fi
55+
- name: Prepare environment
56+
run: |
57+
if [[ -f builder/docker.sh ]]; then
58+
curl --silent --location --output ~/buildkitd-gha.toml \
59+
"https://github.com/mbT-Infrastructure/template-config-files/raw/refs/\
60+
heads/main/debian/buildkit/buildkitd-gha.toml"
61+
docker buildx create --buildkitd-config ~/buildkitd-gha.toml --use
62+
fi
63+
- name: Build
64+
if: ${{ github.event_name != 'schedule'}}
65+
run: |
66+
if [[ ${{ github.ref }} == 'refs/heads/main' ]]; then
67+
builder/build.sh --publish
68+
else
69+
builder/build.sh
70+
fi
71+
- name: Build update base
72+
if: ${{ github.event_name == 'schedule'}}
73+
run: builder/build.sh --publish --update-base
74+
- name: Upload
75+
uses: actions/upload-artifact@v4
76+
with:
77+
name: ${{ env.version }}
78+
path: builds/*
79+
- name: Prepare release files
80+
if: ${{ github.ref == 'refs/heads/main' && env.latest_version != env.version }}
81+
run: |
82+
docker run --pull missing --rm --volume "${PWD}/builds:/media/workdir" \
83+
madebytimo/scripts bash -c \
84+
"split-big-files.sh --size 2147483647 --replace --output /media/workdir \
85+
/media/workdir/*"
86+
- name: Release
87+
if: ${{ github.ref == 'refs/heads/main' && env.latest_version != env.version }}
88+
uses: softprops/action-gh-release@v2
89+
with:
90+
files: builds/*
91+
tag_name: ${{ env.version }}
92+
- name: Export cache
93+
run: |
94+
docker run --pull missing --rm \
95+
--volume "/media/saved-cache:/media/saved-cache" \
96+
--volume \
97+
"docker-scripts-build-cache:/media/build-cache" \
98+
madebytimo/scripts \
99+
compress.sh --fast --output /media/saved-cache/build-cache /media/build-cache
100+
sudo chown -R "$(whoami)" /media/saved-cache
101+
- name: Delete old caches
102+
env:
103+
GH_TOKEN: ${{ github.token }}
104+
run: |
105+
for CACHE in $(gh cache list --key Factory-build-cache --ref ${{ github.ref}} \
106+
| cut --fields 1); do
107+
echo "Deleting cache \"$CACHE\"."
108+
gh cache delete "$CACHE"
109+
done
110+
- name: Set cache
111+
uses: actions/cache/save@v4
112+
with:
113+
path: /media/saved-cache
114+
key: docker-scripts-build-cache-${{ github.run_id }}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: "Check version increment"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout new
13+
uses: actions/checkout@v4
14+
with:
15+
path: new
16+
- name: Checkout old
17+
uses: actions/checkout@v4
18+
with:
19+
path: old
20+
ref: refs/heads/main
21+
- name: Setup Node.js
22+
uses: actions/setup-node@v4
23+
- name: Download script
24+
run: |
25+
curl --silent --output check-version-increment.sh \
26+
https://gitlab.com/madebyTimo/scripts-development/-/raw/main/scripts/\
27+
check-version-increment.sh \
28+
&& chmod +x check-version-increment.sh
29+
- name: Test version increment
30+
run: |
31+
BRANCH="${GITHUB_HEAD_REF#/ref/head}"
32+
echo "Branch to check: $BRANCH"
33+
if [[ "$BRANCH" == @(feature|bugfix)/* ]]; then
34+
./check-version-increment.sh --file --new new/Version.txt \
35+
--old old/Version.txt
36+
else
37+
[[ $(cat new/Version.txt) == $(cat old/Version.txt) ]]
38+
fi

.github/workflows/docker-build-and-push.yaml

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

.github/workflows/docker-update-base-and-push.yaml

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

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
FROM madebytimo/nodejs
1+
FROM madebytimo/base
22

33
RUN install-autonomous.sh install Basics MetadataEditors \
4-
Scripts ScriptsAdvanced ScriptsDevelopment ScriptsHelper && \
5-
rm -rf /var/lib/apt/lists/*
4+
Scripts ScriptsAdvanced ScriptsDevelopment ScriptsHelper \
5+
&& rm -rf /var/lib/apt/lists/*

Readme.md

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
1-
# Docker image
1+
# Scripts image
22

3-
This Docker image contains some useful Scripts.
3+
This image extends the [base image] by my [scripts], [advanced scripts], [development scripts] and
4+
[helper scripts]. In addition, some required packages are contained.
45

56

7+
## Installation
8+
9+
1. Pull from [Docker Hub], download the package from [Releases] or build using `builder/build.sh`
10+
611
## Development
712

8-
To build and run for development run:
13+
To build and run the docker container for development execute:
14+
915
```bash
1016
docker compose --file docker-compose-dev.yaml up --build
1117
```
1218

13-
To build the image locally run:
14-
```bash
15-
./docker-build.sh
16-
```
19+
This repository contains a [`devcontainer.json`](.devcontainer/devcontainer.json). To develop using
20+
a dev container, ensure you have Docker or an alternative like Podman installed and open the project
21+
in a compatible editor like VSCode. The dev container setup will automatically configure the
22+
development environment.
23+
24+
[base image]: https://github.com/mbT-Infrastructure/docker-base
25+
[Docker Hub]: https://hub.docker.com/r/madebytimo/scripts
26+
[Releases]: https://github.com/mbT-infrastructure/Docker-scripts/releases
27+
[scripts]: https://gitlab.com/madebyTimo/scripts
28+
[advanced scripts]: https://gitlab.com/madebyTimo/scripts-advanced
29+
[development scripts]: https://gitlab.com/madebyTimo/scripts-development
30+
[helper scripts]: https://github.com/mbT-Solutions/scripts-helper

Version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v0.1.0
1+
v0.2.0

builder/build.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
set -e -o pipefail
3+
4+
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
5+
6+
# help message
7+
for ARGUMENT in "$@"; do
8+
if [ "$ARGUMENT" == "-h" ] || [ "$ARGUMENT" == "--help" ]; then
9+
echo "usage: $(basename "$0")"
10+
echo "Run all scripts in the same folder."
11+
echo "All arguments are passed to the build scripts."
12+
exit
13+
fi
14+
done
15+
16+
mapfile -t BUILD_SCRIPTS -d '' < <(find "$SCRIPT_DIR" -name '*.sh' -not -name "$(basename "$0")")
17+
for BUILD_SCRIPT in "${BUILD_SCRIPTS[@]}"; do
18+
echo "Start \"$(basename "${BUILD_SCRIPT}")\""
19+
"$BUILD_SCRIPT" "$@"
20+
echo "Finished \"$(basename "${BUILD_SCRIPT}")\""
21+
done

builder/docker.sh

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#!/usr/bin/env bash
2+
set -e -o pipefail
3+
4+
BUILD_ARGUMENTS=()
5+
BUILDER_EXPORT_ARCHIVE="${BUILDER_EXPORT_ARCHIVE:-true}"
6+
DEPENDENCIES=(docker zstd)
7+
UPDATE_BASE=false
8+
PLATFORMS=(linux/amd64 linux/arm linux/arm64)
9+
REGISTRY="docker.io/madebytimo"
10+
SCRIPT_DIR="$(dirname "$(realpath "$0")")"
11+
APPLICATION_NAME="scripts"
12+
13+
# help message
14+
for ARGUMENT in "$@"; do
15+
if [ "$ARGUMENT" == "-h" ] || [ "$ARGUMENT" == "--help" ]; then
16+
echo "usage: $(basename "$0") [ARGUMENT]"
17+
echo "Builds the docker image from the Dockerfile."
18+
echo "ARGUMENT can be"
19+
echo "--platform PLATFORM Build only for specified platform."
20+
echo "--publish Push the build."
21+
echo "--update-base Only build if newer base image is available."
22+
exit
23+
fi
24+
done
25+
26+
# check dependencies
27+
for CMD in "${DEPENDENCIES[@]}"; do
28+
if [[ -z "$(which "$CMD")" ]]; then
29+
echo "\"${CMD}\" is missing!"
30+
exit 1
31+
fi
32+
done
33+
34+
# check arguments
35+
while [[ -n "$1" ]]; do
36+
if [[ "$1" = "--platform" ]]; then
37+
shift
38+
PLATFORMS=("$1")
39+
elif [[ "$1" = "--update-base" ]]; then
40+
UPDATE_BASE=true
41+
elif [[ "$1" = "--publish" ]]; then
42+
BUILD_ARGUMENTS+=("--push")
43+
fi
44+
shift
45+
done
46+
47+
IMAGE="${REGISTRY}/${APPLICATION_NAME}"
48+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
49+
VERSION="$(cat Version.txt)"
50+
51+
cd "$PROJECT_DIR"
52+
mkdir --parents builds
53+
54+
if [[ "$UPDATE_BASE" == true ]]; then
55+
BASE_IMAGE="$(tac Dockerfile | grep --max-count=1 "^FROM" | cut -d" " -f2)"
56+
docker pull --quiet "$BASE_IMAGE"
57+
BASE_IMAGE_DATE="$(docker image inspect --format="{{ .Created }}" "$BASE_IMAGE" \
58+
| sed 's|^\([^T ]*\)[T ].*$|\1|')"
59+
echo "Base image is $BASE_IMAGE from $BASE_IMAGE_DATE"
60+
docker pull "$IMAGE"
61+
PUSHED_IMAGE_DATE="$(docker image inspect --format="{{ .Created }}" "$IMAGE" \
62+
| sed 's|^\([^T ]*\)[T ].*$|\1|')"
63+
echo "Last pushed image is from $PUSHED_IMAGE_DATE"
64+
if [[ "$BASE_IMAGE_DATE" < "$PUSHED_IMAGE_DATE" ]]; then
65+
echo "Used base image is up to date"
66+
exit;
67+
fi
68+
docker image rm "$IMAGE"
69+
fi
70+
71+
PLATFORMS_STRING="${PLATFORMS[*]}"
72+
BUILD_ARGUMENTS+=(--platform "${PLATFORMS_STRING// /,}")
73+
if [[ "$BUILDER_EXPORT_ARCHIVE" == true ]]; then
74+
OUTPUT_FILE="builds/$(basename "$REGISTRY")-${APPLICATION_NAME}-${VERSION}-oci.tar"
75+
BUILD_ARGUMENTS+=(--output \
76+
"type=oci,dest=${OUTPUT_FILE},compression=zstd,compression-level=19,force-compression=true")
77+
fi
78+
79+
docker buildx build --pull "${BUILD_ARGUMENTS[@]}" \
80+
--tag "${IMAGE}:latest" --tag "${IMAGE}:${VERSION}" \
81+
--tag "${IMAGE}:${VERSION}-$(date "+%Y.%m.%d")" .
82+
83+
if [[ "$BUILDER_EXPORT_ARCHIVE" == true ]]; then
84+
docker pull --quiet quay.io/skopeo/stable > /dev/null
85+
rm -f builds/.temp-docker-archive.tar
86+
for PLATFORM in "${PLATFORMS[@]}"; do
87+
docker run --interactive --network none --rm --volume "${PWD}/builds:/builds" \
88+
quay.io/skopeo/stable copy --additional-tag "${IMAGE}:latest" --additional-tag \
89+
"${IMAGE}:${VERSION}" --additional-tag "${IMAGE}:${VERSION}-$(date "+%Y.%m.%d")" \
90+
--override-arch "${PLATFORM#*/}" --quiet "oci-archive:${OUTPUT_FILE}:latest" \
91+
"docker-archive:builds/.temp-docker-archive.tar"
92+
zstd -19 --force --quiet -T0 builds/.temp-docker-archive.tar \
93+
-o "${OUTPUT_FILE%oci.tar}${PLATFORM#*/}.tar.zst"
94+
rm -f builds/.temp-docker-archive.tar
95+
done
96+
fi

docker-bake.hcl

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

0 commit comments

Comments
 (0)