Skip to content

Commit 5149b05

Browse files
committed
Initial downstream THREDDS image with netCDF-Java patch framework
0 parents  commit 5149b05

7 files changed

Lines changed: 177 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Publish image
2+
3+
on:
4+
push:
5+
tags: ['v*']
6+
7+
permissions:
8+
contents: read
9+
packages: write
10+
11+
env:
12+
REGISTRY: ghcr.io
13+
IMAGE_NAME: ternaustralia/thredds-swiftfix
14+
15+
jobs:
16+
publish:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v6
20+
21+
- name: Read versions
22+
id: versions
23+
shell: bash
24+
run: |
25+
set -a
26+
source versions.env
27+
set +a
28+
echo "base=$THREDDS_BASE_IMAGE" >> "$GITHUB_OUTPUT"
29+
echo "commit=$NETCDF_JAVA_COMMIT" >> "$GITHUB_OUTPUT"
30+
echo "version=$IMAGE_VERSION" >> "$GITHUB_OUTPUT"
31+
32+
- uses: docker/setup-buildx-action@v3
33+
34+
- uses: docker/login-action@v3
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- id: meta
41+
uses: docker/metadata-action@v5
42+
with:
43+
images: ghcr.io/ternaustralia/thredds-swiftfix
44+
tags: |
45+
type=ref,event=tag
46+
type=sha,prefix=sha-
47+
48+
- id: build
49+
uses: docker/build-push-action@v6
50+
with:
51+
context: .
52+
file: Containerfile
53+
push: true
54+
platforms: linux/amd64
55+
tags: ${{ steps.meta.outputs.tags }}
56+
labels: ${{ steps.meta.outputs.labels }}
57+
build-args: |
58+
THREDDS_BASE_IMAGE=${{ steps.versions.outputs.base }}
59+
NETCDF_JAVA_COMMIT=${{ steps.versions.outputs.commit }}
60+
IMAGE_VERSION=${{ steps.versions.outputs.version }}
61+
SOURCE_URL=${{ github.server_url }}/${{ github.repository }}
62+
VCS_REF=${{ github.sha }}
63+
BUILD_DATE=${{ github.event.repository.updated_at }}
64+
65+
- name: Show digest
66+
run: echo 'ghcr.io/ternaustralia/thredds-swiftfix@${{ steps.build.outputs.digest }}'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.log

Containerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
ARG THREDDS_BASE_IMAGE
2+
FROM ${THREDDS_BASE_IMAGE} AS patch-builder
3+
USER root
4+
ARG NETCDF_JAVA_COMMIT
5+
WORKDIR /work
6+
COPY scripts/build-patched-jars.sh /usr/local/bin/build-patched-jars.sh
7+
RUN chmod 0755 /usr/local/bin/build-patched-jars.sh && \
8+
/usr/local/bin/build-patched-jars.sh "${NETCDF_JAVA_COMMIT}" /work/out
9+
10+
ARG THREDDS_BASE_IMAGE
11+
FROM ${THREDDS_BASE_IMAGE}
12+
ARG NETCDF_JAVA_COMMIT
13+
ARG IMAGE_VERSION
14+
ARG SOURCE_URL
15+
ARG VCS_REF
16+
ARG BUILD_DATE
17+
LABEL org.opencontainers.image.source="${SOURCE_URL}" \
18+
org.opencontainers.image.revision="${VCS_REF}" \
19+
org.opencontainers.image.created="${BUILD_DATE}" \
20+
org.opencontainers.image.version="${IMAGE_VERSION}" \
21+
org.opencontainers.image.base.name="${THREDDS_BASE_IMAGE}" \
22+
io.thredds.netcdf-java.commit="${NETCDF_JAVA_COMMIT}"
23+
COPY --from=patch-builder /work/out/cdm-s3-5.9.1.jar \
24+
/usr/local/tomcat/webapps/thredds/WEB-INF/lib/cdm-s3-5.9.1.jar
25+
COPY --from=patch-builder /work/out/cdm-core-5.9.1.jar \
26+
/usr/local/tomcat/webapps/thredds/WEB-INF/lib/cdm-core-5.9.1.jar
27+
COPY --from=patch-builder /work/out/sha256sums.txt \
28+
/opt/thredds-swiftfix/sha256sums.txt

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ternaustralia/thredds-swiftfix starter
2+
3+
This starter builds an OCI image from a pinned official THREDDS 5.8 image and
4+
patches both bundled netCDF-Java 5.9.1 jars.
5+
6+
Before building:
7+
8+
1. Copy `versions.env.example` to `versions.env`.
9+
2. Replace the base-image digest.
10+
3. Replace the netCDF-Java commit SHA.
11+
4. Run:
12+
13+
```bash
14+
docker build -f Containerfile --build-arg THREDDS_BASE_IMAGE="$(grep '^THREDDS_BASE_IMAGE=' versions.env | cut -d= -f2-)" --build-arg NETCDF_JAVA_COMMIT="$(grep '^NETCDF_JAVA_COMMIT=' versions.env | cut -d= -f2-)" --build-arg IMAGE_VERSION="$(grep '^IMAGE_VERSION=' versions.env | cut -d= -f2-)" --build-arg SOURCE_URL='https://github.com/ternaustralia/thredds-swiftfix' --build-arg VCS_REF="$(git rev-parse HEAD)" --build-arg BUILD_DATE="$(date -u +%Y-%m-%dT%H:%M:%SZ)" -t ternaustralia/thredds-swiftfix:local .
15+
```

scripts/build-patched-jars.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
COMMIT="${1:?Missing netCDF-Java commit}"
5+
OUT="${2:?Missing output directory}"
6+
LIB=/usr/local/tomcat/webapps/thredds/WEB-INF/lib
7+
JAVA_HOME="${JAVA_HOME:-/opt/java/openjdk}"
8+
WORK=/tmp/netcdf-java-swiftfix
9+
10+
rm -rf "$WORK" "$OUT"
11+
mkdir -p "$WORK/src/thredds/filesystem/s3" \
12+
"$WORK/src/ucar/nc2/internal/ncml" \
13+
"$WORK/classes/s3" "$WORK/classes/core" "$OUT"
14+
15+
S3="$WORK/src/thredds/filesystem/s3/ControllerS3.java"
16+
CORE="$WORK/src/ucar/nc2/internal/ncml/AggregationExisting.java"
17+
18+
curl -fsSL "https://raw.githubusercontent.com/Unidata/netcdf-java/${COMMIT}/cdm/s3/src/main/java/thredds/filesystem/s3/ControllerS3.java" -o "$S3"
19+
curl -fsSL "https://raw.githubusercontent.com/Unidata/netcdf-java/${COMMIT}/cdm/core/src/main/java/ucar/nc2/internal/ncml/AggregationExisting.java" -o "$CORE"
20+
21+
awk '
22+
{
23+
print
24+
if ($0 ~ /^[[:space:]]*String continuationToken = useV2 \? responseV2\.nextContinuationToken\(\) : responseV1\.nextMarker\(\);[[:space:]]*$/) {
25+
print ""
26+
print " // OpenStack Swift may omit NextMarker for a truncated V1 response."
27+
print " if (!useV2"
28+
print " && continuationToken == null"
29+
print " && responseV1.isTruncated()"
30+
print " && !objects.isEmpty()) {"
31+
print " continuationToken = objects.get(objects.size() - 1).key();"
32+
print " }"
33+
}
34+
}
35+
' "$S3" > "$S3.patched"
36+
mv "$S3.patched" "$S3"
37+
grep -Fq 'continuationToken = objects.get(objects.size() - 1).key();' "$S3"
38+
39+
OLD='Parse.readRootElement("file:" + cacheFile.getPath())'
40+
NEW='Parse.readRootElement(cacheFile.toURI().toString())'
41+
grep -Fq "$OLD" "$CORE"
42+
sed -i "s@${OLD}@${NEW}@" "$CORE"
43+
grep -Fq "$NEW" "$CORE"
44+
45+
"$JAVA_HOME/bin/javac" -proc:none -cp "$LIB/*" -d "$WORK/classes/s3" "$S3"
46+
"$JAVA_HOME/bin/javac" -proc:none -cp "$LIB/*" -d "$WORK/classes/core" "$CORE"
47+
48+
cp "$LIB/cdm-s3-5.9.1.jar" "$OUT/cdm-s3-5.9.1.jar"
49+
cp "$LIB/cdm-core-5.9.1.jar" "$OUT/cdm-core-5.9.1.jar"
50+
51+
"$JAVA_HOME/bin/jar" --update --file "$OUT/cdm-s3-5.9.1.jar" \
52+
-C "$WORK/classes/s3" thredds/filesystem/s3
53+
"$JAVA_HOME/bin/jar" --update --file "$OUT/cdm-core-5.9.1.jar" \
54+
-C "$WORK/classes/core" ucar/nc2/internal/ncml/AggregationExisting.class
55+
56+
"$JAVA_HOME/bin/javap" -classpath "$OUT/cdm-core-5.9.1.jar" -c -p \
57+
ucar.nc2.internal.ncml.AggregationExisting | grep -q 'java/io/File.toURI'
58+
59+
sha256sum "$OUT/cdm-s3-5.9.1.jar" "$OUT/cdm-core-5.9.1.jar" \
60+
> "$OUT/sha256sums.txt"
61+
cat "$OUT/sha256sums.txt"

versions.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
THREDDS_BASE_IMAGE=docker.io/unidata/thredds-docker:5.8@sha256:5dcec410058ee0fa4f55debe5152ee53fe0e82f5e4d9bccf70f05ca1a228d95f
2+
NETCDF_JAVA_COMMIT=647155bae55ff3ce7ce2d518ffa7621d721d4f0f
3+
IMAGE_VERSION=5.8-ncj5.9.1-r1

versions.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
THREDDS_BASE_IMAGE=docker.io/unidata/thredds-docker:5.8@sha256:REPLACE_ME
2+
NETCDF_JAVA_COMMIT=REPLACE_WITH_FULL_40_CHARACTER_SHA
3+
IMAGE_VERSION=5.8-ncj5.9.1-r1

0 commit comments

Comments
 (0)