diff options
author | 2024-06-24 15:58:16 +0200 | |
---|---|---|
committer | 2024-06-24 19:26:47 +0200 | |
commit | d46a69a43f5662947a81286adcb8f452163cfdf5 (patch) | |
tree | b6251a20d2979f019b45d9ee5bec16ef3011799c /docker | |
parent | fix(frontend): Algolia search (diff) | |
download | refinery-d46a69a43f5662947a81286adcb8f452163cfdf5.tar.gz refinery-d46a69a43f5662947a81286adcb8f452163cfdf5.tar.zst refinery-d46a69a43f5662947a81286adcb8f452163cfdf5.zip |
build: create Docker images automatically
Diffstat (limited to 'docker')
-rw-r--r-- | docker/.gitignore | 5 | ||||
-rwxr-xr-x | docker/bake.sh | 17 | ||||
-rwxr-xr-x | docker/build.sh | 48 | ||||
-rw-r--r-- | docker/context/Dockerfile.base (renamed from docker/Dockerfile.base) | 11 | ||||
-rw-r--r-- | docker/context/Dockerfile.cli (renamed from docker/Dockerfile.cli) | 8 | ||||
-rw-r--r-- | docker/context/Dockerfile.web (renamed from docker/Dockerfile.web) | 8 | ||||
-rw-r--r-- | docker/context/docker-bake.hcl | 43 | ||||
-rw-r--r-- | docker/docker-bake.hcl | 44 | ||||
-rwxr-xr-x | docker/get_version.sh | 9 | ||||
-rwxr-xr-x | docker/prepare_context.sh | 66 |
10 files changed, 156 insertions, 103 deletions
diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 00000000..64089f92 --- /dev/null +++ b/docker/.gitignore | |||
@@ -0,0 +1,5 @@ | |||
1 | # SPDX-FileCopyrightText: 2024 The Refinery Authors | ||
2 | # | ||
3 | # SPDX-License-Identifier: CC0-1.0 | ||
4 | |||
5 | context/extracted | ||
diff --git a/docker/bake.sh b/docker/bake.sh new file mode 100755 index 00000000..67b05a52 --- /dev/null +++ b/docker/bake.sh | |||
@@ -0,0 +1,17 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
4 | # | ||
5 | # SPDX-License-Identifier: EPL-2.0 | ||
6 | |||
7 | set -euo pipefail | ||
8 | |||
9 | REFINERY_VERSION="$(./get_version.sh)" | ||
10 | export REFINERY_VERSION | ||
11 | |||
12 | export REFINERY_PUSH="${1-false}" | ||
13 | |||
14 | export SOURCE_DATE_EPOCH=0 | ||
15 | |||
16 | cd context | ||
17 | exec docker buildx bake -f docker-bake.hcl "${@:2}" | ||
diff --git a/docker/build.sh b/docker/build.sh index 8a03e6d5..2f5ba270 100755 --- a/docker/build.sh +++ b/docker/build.sh | |||
@@ -1,6 +1,6 @@ | |||
1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
2 | 2 | ||
3 | # SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/> | 3 | # SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> |
4 | # | 4 | # |
5 | # SPDX-License-Identifier: EPL-2.0 | 5 | # SPDX-License-Identifier: EPL-2.0 |
6 | 6 | ||
@@ -8,48 +8,6 @@ set -euo pipefail | |||
8 | 8 | ||
9 | (cd .. && ./gradlew distTar) | 9 | (cd .. && ./gradlew distTar) |
10 | 10 | ||
11 | refinery_version="$(grep '^version=' ../gradle.properties | cut -d'=' -f2)" | 11 | ./prepare_context.sh |
12 | cli_distribution_name="refinery-generator-cli-${refinery_version}" | ||
13 | web_distribution_name="refinery-language-web-${refinery_version}" | ||
14 | 12 | ||
15 | rm -rf "${cli_distribution_name}" "${web_distribution_name}" {cli,web}_dist \ | 13 | ./bake.sh "${1-false}" "${@:2}" |
16 | {cli,web}_{,app_}lib common_{,amd64_,arm64_}lib {cli,web}_{amd64,arm64}_bin | ||
17 | |||
18 | tar -xf "../subprojects/generator-cli/build/distributions/${cli_distribution_name}.tar" | ||
19 | mv "${cli_distribution_name}" cli_dist | ||
20 | tar -xf "../subprojects/language-web/build/distributions/${web_distribution_name}.tar" | ||
21 | mv "${web_distribution_name}" web_dist | ||
22 | mkdir -p {cli,web}_{,app_}lib common_{,amd64_,arm64_}lib {cli,web}_{amd64,arm64}_bin | ||
23 | |||
24 | # Our application itself is very small, so it will get added as the last layer | ||
25 | # of both containers. | ||
26 | mv cli_dist/lib/refinery-* cli_app_lib | ||
27 | mv web_dist/lib/refinery-* web_app_lib | ||
28 | |||
29 | for i in cli_dist/lib/*; do | ||
30 | j="web${i#cli}" | ||
31 | if [[ -f "$j" ]]; then | ||
32 | mv "$i" "common_lib${i#cli_dist/lib}" | ||
33 | rm "$j" | ||
34 | fi | ||
35 | done | ||
36 | |||
37 | # Move architecture-specific jars to their repsective directories. | ||
38 | mv common_lib/ortools-linux-x86-64-*.jar common_amd64_lib | ||
39 | mv common_lib/ortools-linux-aarch64-*.jar common_arm64_lib | ||
40 | rm common_lib/ortools-{darwin,win32}-*.jar | ||
41 | # Move the applications jars for the dependencies into a separate Docker layer | ||
42 | # to enable faster updates. | ||
43 | mv cli_dist/lib/* cli_lib | ||
44 | mv web_dist/lib/* web_lib | ||
45 | # Omit references to jars not present for the current architecture from the | ||
46 | # startup scripts. | ||
47 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' cli_dist/bin/refinery-generator-cli > cli_amd64_bin/refinery-generator-cli | ||
48 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' cli_dist/bin/refinery-generator-cli > cli_arm64_bin/refinery-generator-cli | ||
49 | chmod a+x cli_{amd64,arm64}_bin/refinery-generator-cli | ||
50 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' web_dist/bin/refinery-language-web > web_amd64_bin/refinery-language-web | ||
51 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' web_dist/bin/refinery-language-web > web_arm64_bin/refinery-language-web | ||
52 | chmod a+x web_{amd64,arm64}_bin/refinery-language-web | ||
53 | rm -rf {cli,web}_dist | ||
54 | |||
55 | REFINERY_VERSION="${refinery_version}" docker buildx bake -f docker-bake.hcl | ||
diff --git a/docker/Dockerfile.base b/docker/context/Dockerfile.base index 0668ce78..c73f2c4c 100644 --- a/docker/Dockerfile.base +++ b/docker/context/Dockerfile.base | |||
@@ -30,8 +30,8 @@ RUN apt-get update && \ | |||
30 | ln -sf /usr/bin/x86_64-linux-gnu-objcopy /usr/bin/objcopy && \ | 30 | ln -sf /usr/bin/x86_64-linux-gnu-objcopy /usr/bin/objcopy && \ |
31 | rm -rf /var/lib/apt/lists/* | 31 | rm -rf /var/lib/apt/lists/* |
32 | 32 | ||
33 | FROM --platform=$BUILDPLATFORM jlink-$TARGETARCH-on-$BUILDARCH as jlink | 33 | FROM --platform=$BUILDPLATFORM jlink-$TARGETARCH-on-$BUILDARCH AS jlink |
34 | RUN jlink --no-header-files --no-man-pages --compress=2 \ | 34 | RUN jlink --no-header-files --no-man-pages \ |
35 | --module-path=/crossjdk/jmods --strip-debug --add-modules \ | 35 | --module-path=/crossjdk/jmods --strip-debug --add-modules \ |
36 | java.base,java.logging,java.xml,jdk.zipfs \ | 36 | java.base,java.logging,java.xml,jdk.zipfs \ |
37 | --output /jlink | 37 | --output /jlink |
@@ -44,15 +44,14 @@ RUN dnf install -y findutils && \ | |||
44 | COPY --link --from=jlink /jlink /usr/lib/java | 44 | COPY --link --from=jlink /jlink /usr/lib/java |
45 | ENV JAVA_HOME="/usr/lib/java" PATH="/usr/lib/java/bin:${PATH}" | 45 | ENV JAVA_HOME="/usr/lib/java" PATH="/usr/lib/java/bin:${PATH}" |
46 | # Layer with platform-independent dependencies, slow changing. | 46 | # Layer with platform-independent dependencies, slow changing. |
47 | ADD --link common_lib /app/lib | 47 | ADD --link extracted/common_lib /app/lib |
48 | 48 | ||
49 | FROM base AS base-amd64 | 49 | FROM base AS base-amd64 |
50 | # Layer with platform-dependent dependencies, slow changing. | 50 | # Layer with platform-dependent dependencies, slow changing. |
51 | ADD --link common_amd64_lib /app/lib | 51 | ADD --link extracted/common_amd64_lib /app/lib |
52 | 52 | ||
53 | FROM base AS base-arm64 | 53 | FROM base AS base-arm64 |
54 | # Layer with platform-dependent dependencies, slow changing. | 54 | # Layer with platform-dependent dependencies, slow changing. |
55 | ADD --link common_arm64_lib /app/lib | 55 | ADD --link extracted/common_arm64_lib /app/lib |
56 | 56 | ||
57 | FROM base-$TARGETARCH | 57 | FROM base-$TARGETARCH |
58 | |||
diff --git a/docker/Dockerfile.cli b/docker/context/Dockerfile.cli index 54396d4e..ddfb6b29 100644 --- a/docker/Dockerfile.cli +++ b/docker/context/Dockerfile.cli | |||
@@ -4,21 +4,21 @@ | |||
4 | 4 | ||
5 | FROM base AS cli-base | 5 | FROM base AS cli-base |
6 | # Layer with platform-dependent dependencies, slow changing. | 6 | # Layer with platform-dependent dependencies, slow changing. |
7 | ADD --link cli_lib /app/lib | 7 | ADD --link extracted/cli_lib /app/lib |
8 | 8 | ||
9 | FROM cli-base AS cli-amd64 | 9 | FROM cli-base AS cli-amd64 |
10 | # Layer with platform-dependent startup script containing references to all | 10 | # Layer with platform-dependent startup script containing references to all |
11 | # dependency versions. | 11 | # dependency versions. |
12 | ADD --link cli_amd64_bin /app/bin | 12 | ADD --link extracted/cli_amd64_bin /app/bin |
13 | 13 | ||
14 | FROM cli-base AS cli-arm64 | 14 | FROM cli-base AS cli-arm64 |
15 | # Layer with platform-dependent startup script containing references to all | 15 | # Layer with platform-dependent startup script containing references to all |
16 | # dependency versions. | 16 | # dependency versions. |
17 | ADD --link cli_arm64_bin /app/bin | 17 | ADD --link extracted/cli_arm64_bin /app/bin |
18 | 18 | ||
19 | FROM cli-$TARGETARCH | 19 | FROM cli-$TARGETARCH |
20 | # Layer with platform-independent application jars. | 20 | # Layer with platform-independent application jars. |
21 | ADD --link cli_app_lib /app/lib | 21 | ADD --link extracted/cli_app_lib /app/lib |
22 | # Common settings added on top. | 22 | # Common settings added on top. |
23 | ENV REFINERY_LIBRARY_PATH=/data | 23 | ENV REFINERY_LIBRARY_PATH=/data |
24 | USER 1000 | 24 | USER 1000 |
diff --git a/docker/Dockerfile.web b/docker/context/Dockerfile.web index dd25662e..9c2874c8 100644 --- a/docker/Dockerfile.web +++ b/docker/context/Dockerfile.web | |||
@@ -4,21 +4,21 @@ | |||
4 | 4 | ||
5 | FROM base AS web-base | 5 | FROM base AS web-base |
6 | # Layer with platform-dependent dependencies, slow changing. | 6 | # Layer with platform-dependent dependencies, slow changing. |
7 | ADD --link web_lib /app/lib | 7 | ADD --link extracted/web_lib /app/lib |
8 | 8 | ||
9 | FROM web-base AS web-amd64 | 9 | FROM web-base AS web-amd64 |
10 | # Layer with platform-dependent startup script containing references to all | 10 | # Layer with platform-dependent startup script containing references to all |
11 | # dependency versions. | 11 | # dependency versions. |
12 | ADD --link web_amd64_bin /app/bin | 12 | ADD --link extracted/web_amd64_bin /app/bin |
13 | 13 | ||
14 | FROM web-base AS web-arm64 | 14 | FROM web-base AS web-arm64 |
15 | # Layer with platform-dependent startup script containing references to all | 15 | # Layer with platform-dependent startup script containing references to all |
16 | # dependency versions. | 16 | # dependency versions. |
17 | ADD --link web_arm64_bin /app/bin | 17 | ADD --link extracted/web_arm64_bin /app/bin |
18 | 18 | ||
19 | FROM web-$TARGETARCH | 19 | FROM web-$TARGETARCH |
20 | # Layer with platform-independent application jars. | 20 | # Layer with platform-independent application jars. |
21 | ADD --link web_app_lib /app/lib | 21 | ADD --link extracted/web_app_lib /app/lib |
22 | # Common settings added on top. | 22 | # Common settings added on top. |
23 | ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888 | 23 | ENV REFINERY_LISTEN_HOST=0.0.0.0 REFINERY_LISTEN_PORT=8888 |
24 | EXPOSE 8888 | 24 | EXPOSE 8888 |
diff --git a/docker/context/docker-bake.hcl b/docker/context/docker-bake.hcl new file mode 100644 index 00000000..3c388627 --- /dev/null +++ b/docker/context/docker-bake.hcl | |||
@@ -0,0 +1,43 @@ | |||
1 | # SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
2 | # | ||
3 | # SPDX-License-Identifier: EPL-2.0 | ||
4 | |||
5 | variable "REFINERY_VERSION" { | ||
6 | default = "" | ||
7 | } | ||
8 | |||
9 | variable "REFINERY_PUSH" { | ||
10 | default = "false" | ||
11 | } | ||
12 | |||
13 | group "default" { | ||
14 | targets = ["cli", "web"] | ||
15 | } | ||
16 | |||
17 | target "base" { | ||
18 | dockerfile = "Dockerfile.base" | ||
19 | platforms = ["linux/amd64", "linux/arm64"] | ||
20 | output = ["type=cacheonly"] | ||
21 | } | ||
22 | |||
23 | target "cli" { | ||
24 | dockerfile = "Dockerfile.cli" | ||
25 | platforms = ["linux/amd64", "linux/arm64"] | ||
26 | output = [ | ||
27 | "type=image,push=${REFINERY_PUSH},\"name=ghcr.io/graphs4value/refinery-cli:${REFINERY_VERSION},ghcr.io/graphs4value/refinery-cli:latest\",annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,\"annotation-index.org.opencontainers.image.description=Command line interface for Refinery, an efficient graph solver for generating well-formed models\",annotation-index.org.opencontainers.image.licenses=EPL-2.0" | ||
28 | ] | ||
29 | contexts = { | ||
30 | base = "target:base" | ||
31 | } | ||
32 | } | ||
33 | |||
34 | target "web" { | ||
35 | dockerfile = "Dockerfile.web" | ||
36 | platforms = ["linux/amd64", "linux/arm64"] | ||
37 | output = [ | ||
38 | "type=image,push=${REFINERY_PUSH},\"name=ghcr.io/graphs4value/refinery:${REFINERY_VERSION},ghcr.io/graphs4value/refinery:latest\",annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,annotation-index.org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models,annotation-index.org.opencontainers.image.licenses=EPL-2.0" | ||
39 | ] | ||
40 | contexts = { | ||
41 | base = "target:base" | ||
42 | } | ||
43 | } | ||
diff --git a/docker/docker-bake.hcl b/docker/docker-bake.hcl deleted file mode 100644 index 0a84e0a3..00000000 --- a/docker/docker-bake.hcl +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | # SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
2 | # | ||
3 | # SPDX-License-Identifier: EPL-2.0 | ||
4 | |||
5 | variable "REFINERY_VERSION" { | ||
6 | default = "" | ||
7 | } | ||
8 | |||
9 | variable "REFINERY_ANNOTATIONS" { | ||
10 | default = "" | ||
11 | } | ||
12 | |||
13 | group "default" { | ||
14 | targets = ["cli", "web"] | ||
15 | } | ||
16 | |||
17 | target "base" { | ||
18 | dockerfile = "Dockerfile.base" | ||
19 | platforms = ["linux/amd64", "linux/arm64"] | ||
20 | output = ["type=cacheonly"] | ||
21 | } | ||
22 | |||
23 | target "cli" { | ||
24 | dockerfile = "Dockerfile.cli" | ||
25 | platforms = ["linux/amd64", "linux/arm64"] | ||
26 | output = [ | ||
27 | "type=image,\"name=ghcr.io/graphs4value/refinery-cli:${REFINERY_VERSION},ghcr.io/graphs4value/refinery-cli:latest\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,\"annotation-index.org.opencontainers.image.description=Command line interface for Refinery, an efficient graph solver for generating well-formed models\",annotation-index.org.opencontainers.image.licenses=EPL-2.0" | ||
28 | ] | ||
29 | contexts = { | ||
30 | base = "target:base" | ||
31 | } | ||
32 | } | ||
33 | |||
34 | target "web" { | ||
35 | dockerfile = "Dockerfile.web" | ||
36 | platforms = ["linux/amd64", "linux/arm64"] | ||
37 | output = [ | ||
38 | "type=image,\"name=ghcr.io/graphs4value/refinery:${REFINERY_VERSION},ghcr.io/graphs4value/refinery:latest\",push=true,annotation-index.org.opencontainers.image.source=https://github.com/graphs4value/refinery,annotation-index.org.opencontainers.image.description=Refinery: an efficient graph solver for generating well-formed models,annotation-index.org.opencontainers.image.licenses=EPL-2.0" | ||
39 | |||
40 | ] | ||
41 | contexts = { | ||
42 | base = "target:base" | ||
43 | } | ||
44 | } | ||
diff --git a/docker/get_version.sh b/docker/get_version.sh new file mode 100755 index 00000000..f507d060 --- /dev/null +++ b/docker/get_version.sh | |||
@@ -0,0 +1,9 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/> | ||
4 | # | ||
5 | # SPDX-License-Identifier: EPL-2.0 | ||
6 | |||
7 | set -euo pipefail | ||
8 | |||
9 | grep '^version=' ../gradle.properties | cut -d'=' -f2 | ||
diff --git a/docker/prepare_context.sh b/docker/prepare_context.sh new file mode 100755 index 00000000..ca8bf500 --- /dev/null +++ b/docker/prepare_context.sh | |||
@@ -0,0 +1,66 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | |||
3 | # SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/> | ||
4 | # | ||
5 | # SPDX-License-Identifier: EPL-2.0 | ||
6 | |||
7 | set -euo pipefail | ||
8 | |||
9 | refinery_version="$(./get_version.sh)" | ||
10 | cli_distribution_name="refinery-generator-cli-${refinery_version}" | ||
11 | web_distribution_name="refinery-language-web-${refinery_version}" | ||
12 | |||
13 | rm -rf "${cli_distribution_name}" "${web_distribution_name}" {cli,web}_dist context/extracted | ||
14 | |||
15 | tar -xvf "../subprojects/generator-cli/build/distributions/${cli_distribution_name}.tar" | ||
16 | mv "${cli_distribution_name}" cli_dist | ||
17 | tar -xvf "../subprojects/language-web/build/distributions/${web_distribution_name}.tar" | ||
18 | mv "${web_distribution_name}" web_dist | ||
19 | mkdir -p context/extracted/{cli,web}_{,app_}lib \ | ||
20 | context/extracted/common_{,amd64_,arm64_}lib \ | ||
21 | context/extracted/{cli,web}_{amd64,arm64}_bin | ||
22 | |||
23 | move_application_jars() { | ||
24 | prefix="$1" | ||
25 | # Our application itself is very small, so it will get added as the last layer | ||
26 | # of both containers. | ||
27 | mv "${prefix}"_dist/lib/refinery-* "context/extracted/${prefix}_app_lib" | ||
28 | } | ||
29 | |||
30 | move_application_jars cli | ||
31 | move_application_jars web | ||
32 | |||
33 | for i in cli_dist/lib/*; do | ||
34 | j="web${i#cli}" | ||
35 | if [[ -f "$j" ]]; then | ||
36 | mv "$i" "context/extracted/common_lib${i#cli_dist/lib}" | ||
37 | rm "$j" | ||
38 | fi | ||
39 | done | ||
40 | |||
41 | # Move architecture-specific jars to their repsective directories. | ||
42 | mv context/extracted/common_lib/ortools-linux-x86-64-*.jar context/extracted/common_amd64_lib | ||
43 | mv context/extracted/common_lib/ortools-linux-aarch64-*.jar context/extracted/common_arm64_lib | ||
44 | rm context/extracted/common_lib/ortools-{darwin,win32}-*.jar | ||
45 | |||
46 | prepare_application() { | ||
47 | prefix="$1" | ||
48 | suffix="$2" | ||
49 | # Move the applications jars for the dependencies into a separate Docker layer | ||
50 | # to enable faster updates. | ||
51 | mv "${prefix}"_dist/lib/* "context/extracted/${prefix}_lib" | ||
52 | # Omit references to jars not present for the current architecture from the | ||
53 | # startup scripts. | ||
54 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-aarch64\)[^:]\+\.jar//g' \ | ||
55 | "${prefix}_dist/bin/refinery-${suffix}" \ | ||
56 | > "context/extracted/${prefix}_amd64_bin/refinery-${suffix}" | ||
57 | sed 's/:\$APP_HOME\/lib\/ortools-\(darwin\|win32\|linux-x86-64\)[^:]\+\.jar//g' \ | ||
58 | "${prefix}_dist/bin/refinery-${suffix}" \ | ||
59 | > "context/extracted/${prefix}_arm64_bin/refinery-${suffix}" | ||
60 | chmod a+x "context/extracted/${prefix}"_{amd64,arm64}_bin/refinery-"${suffix}" | ||
61 | } | ||
62 | |||
63 | prepare_application cli generator-cli | ||
64 | prepare_application web language-web | ||
65 | |||
66 | rm -rf {cli,web}_dist | ||