Skip to content

Commit 5ab5f85

Browse files
authored
Merge pull request #1440 from swisstopo/develop
INT Release
2 parents 044ec78 + a77f819 commit 5ab5f85

File tree

330 files changed

+19094
-15709
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

330 files changed

+19094
-15709
lines changed

.editorconfig

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
root = true
2-
3-
[*.js]
4-
indent_style = space
5-
indent_size = 2
6-
charset = utf-8
7-
trim_trailing_whitespace = true
8-
insert_final_newline = true
9-
10-
[*.md]
11-
trim_trailing_whitespace = false
1+
root = true
2+
3+
[{*.js,*.ts}]
4+
indent_style = space
5+
indent_size = 2
6+
charset = utf-8
7+
trim_trailing_whitespace = true
8+
insert_final_newline = true
9+
10+
[*.md]
11+
trim_trailing_whitespace = false

.env

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Database
2+
PGUSER=www-data
3+
PGPASSWORD=www-data
4+
PGHOST=db
5+
PGPORT=5432
6+
PGDATABASE=swissgeol-local
7+
8+
# SQLx
9+
DATABASE_URL=postgres://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}
10+
11+
# S3
12+
S3_AWS_REGION=eu-west-1
13+
AWS_ACCESS_KEY_ID=minio
14+
AWS_SECRET_ACCESS_KEY=minio123

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
package-lock.json -diff
1+
* -text
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: "Create Docker Image"
2+
description: "Builds a docker image and tags it"
3+
inputs:
4+
IMAGE_NAME:
5+
description: "The image name"
6+
required: true
7+
VERSION:
8+
description: "The version of the image"
9+
required: true
10+
TAG:
11+
description: "The tag of the image, in addition to the version"
12+
required: true
13+
OTHER_TAGS:
14+
description: "Any additional tags, passed directly to docker/metadata-action"
15+
DOCKERFILE:
16+
description: "The path to the Dockerfile"
17+
required: true
18+
GITHUB_TOKEN:
19+
description: "The github token"
20+
required: true
21+
CONTEXT:
22+
description: "The build context"
23+
default: "./"
24+
required: false
25+
26+
runs:
27+
using: "composite"
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set environment variables
33+
shell: bash
34+
run: |
35+
echo COMMITED_AT=$(git show -s --format=%cI ${{ github.sha }}) >> $GITHUB_ENV
36+
echo REVISION=$(git rev-parse --short HEAD) >> $GITHUB_ENV
37+
38+
- name: Collect docker image metadata
39+
id: meta-data
40+
uses: docker/metadata-action@v5
41+
with:
42+
images: ${{ inputs.IMAGE_NAME }}
43+
labels: |
44+
org.opencontainers.image.created=${{ env.COMMITED_AT }}
45+
org.opencontainers.image.version=v${{ inputs.VERSION }}
46+
org.opencontainers.image.maintainer=EBP Schweiz AG
47+
flavor: |
48+
latest=${{ inputs.TAG == 'latest' }}
49+
tags: |
50+
type=raw,value=${{ inputs.TAG }}
51+
type=raw,value=${{ inputs.VERSION }}
52+
${{ inputs.OTHER_TAGS }}
53+
54+
- name: Log in to the GitHub container registry
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.repository_owner }}
59+
password: ${{ inputs.GITHUB_TOKEN }}
60+
61+
- name: Build and push Docker image
62+
uses: docker/build-push-action@v5
63+
with:
64+
context: ${{ inputs.CONTEXT }}
65+
file: ${{ inputs.DOCKERFILE }}
66+
push: true
67+
tags: ${{ steps.meta-data.outputs.tags }}
68+
labels: ${{ steps.meta-data.outputs.labels }}
69+
no-cache: true
70+
build-args: |
71+
APP_VERSION=${{ inputs.VERSION }}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: "Tag Commit"
2+
description: "Creates or updates a commit tag"
3+
inputs:
4+
TAG_NAME:
5+
description: "The tag's name"
6+
required: true
7+
SHA:
8+
description: "The SHA of the commit to be tagged"
9+
required: true
10+
11+
runs:
12+
using: "composite"
13+
steps:
14+
- name: Create/update tag
15+
uses: actions/github-script@v7
16+
env:
17+
TAG: ${{ inputs.TAG_NAME }}
18+
SHA: ${{ inputs.SHA }}
19+
with:
20+
script: |
21+
github.rest.git.createRef({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
ref: `refs/tags/${process.env.TAG}`,
25+
sha: process.env.SHA
26+
}).catch(err => {
27+
if (err.status !== 422) throw err;
28+
github.rest.git.updateRef({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
ref: `tags/${process.env.TAG}`,
32+
sha: process.env.SHA
33+
});
34+
})

.github/scripts/find-version.js

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
const findNextVersion = (tags, branch) => {
2+
const version = findMostRecentVersion(tags);
3+
if (branch.startsWith("feature/")) {
4+
// It's a minor feature.
5+
6+
// If the previous version was a full release or a patch dev release,
7+
// we are a completely new minor dev release.
8+
// Otherwise, the previous version was itself a minor dev release,
9+
// and we can reuse its number.
10+
if (version.preRelease == null || version.patch !== 0) {
11+
version.minor += 1;
12+
version.patch = 0;
13+
version.preRelease = null
14+
}
15+
} else {
16+
// It's a patch.
17+
18+
// If the previous version was a full release,
19+
// we are a completely new patch dev release.
20+
// Otherwise, we can simply reuse the previous version's number.
21+
if (version.preRelease == null) {
22+
version.patch += 1;
23+
}
24+
}
25+
26+
version.preRelease ??= 0;
27+
version.preRelease += 1;
28+
return version;
29+
};
30+
31+
const findMostRecentVersion = (tags) => {
32+
const versions = findAllVersions(tags);
33+
if (versions.length === 0) {
34+
throw new Error("unable to find a valid version on current edge tag");
35+
}
36+
return versions[0];
37+
};
38+
39+
const findOutdatedVersions = (tags, recentTag) => {
40+
const recentVersion = parseVersion(recentTag);
41+
if (recentVersion == null) {
42+
throw new Error(`recent tag '${recentTag}' is not a version number`);
43+
}
44+
const versions = findAllVersions(tags);
45+
return versions.filter(
46+
(version) =>
47+
// Select all pre-releases that appear before the most recent one.
48+
version.preRelease != null && compareVersions(recentVersion, version) > 0
49+
);
50+
};
51+
52+
const findAllVersions = (tags) => {
53+
return tags
54+
.map(parseVersion)
55+
.filter((it) => it != null)
56+
.sort((a, b) => compareVersions(a, b) * -1);
57+
};
58+
59+
const SEMANTIC_VERSION_PATTERN = /^\d+\.\d+\.\d+(?:-dev\d+)?$/;
60+
const parseVersion = (tag) => {
61+
if (!SEMANTIC_VERSION_PATTERN.test(tag)) {
62+
return null;
63+
}
64+
const [major, minor, patch, preRelease] = tag.split(/[.\-]/);
65+
return {
66+
major: parseInt(major),
67+
minor: parseInt(minor),
68+
patch: parseInt(patch),
69+
preRelease: preRelease && parseInt(preRelease.substring(3)),
70+
};
71+
};
72+
73+
const compareVersions = (a, b) => {
74+
if (a.major !== b.major) {
75+
return a.major - b.major;
76+
}
77+
if (a.minor !== b.minor) {
78+
return a.minor - b.minor;
79+
}
80+
if (a.patch !== b.patch) {
81+
return a.patch - b.patch;
82+
}
83+
if (a.preRelease !== b.preRelease) {
84+
if (a.preRelease == null) {
85+
return 1;
86+
}
87+
if (b.preRelease == null) {
88+
return -1;
89+
}
90+
return a.preRelease - b.preRelease;
91+
}
92+
return 0;
93+
};
94+
95+
const makeVersionTag = ({ major, minor, patch, preRelease }) => {
96+
const tag = `${major}.${minor}.${patch}`;
97+
if (preRelease == null) {
98+
return tag;
99+
}
100+
return `${tag}-dev${preRelease}`;
101+
};
102+
103+
module.exports = {
104+
findNextVersion,
105+
findMostRecentVersion,
106+
findOutdatedVersions,
107+
makeVersionTag,
108+
};

.github/scripts/remove-packages.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const removePackageVersions = async (imageUrl, imageVersions) => {
2+
const { Octokit } = await import("@octokit/rest");
3+
4+
const octokit = new Octokit({
5+
auth: process.env.GITHUB_TOKEN,
6+
});
7+
8+
const [_imageHost, imageOwner, imageName] = imageUrl.split("/");
9+
const imageIds = await loadOutdatedVersionIds(octokit, imageOwner, imageName, imageVersions);
10+
for (const imageId of imageIds) {
11+
await octokit.rest.packages.deletePackageVersionForOrg({
12+
package_type: "container",
13+
package_name: imageName,
14+
org: imageOwner,
15+
package_version_id: imageId,
16+
});
17+
}
18+
};
19+
20+
const loadOutdatedVersionIds = async (octokit, imageOwner, imageName, versions) => {
21+
let page = 0;
22+
versions = new Set(versions);
23+
24+
const ids = new Set();
25+
while (true) {
26+
const response = await octokit.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({
27+
package_type: "container",
28+
package_name: imageName,
29+
org: imageOwner,
30+
page,
31+
});
32+
if (response.data.length === 0) {
33+
break;
34+
}
35+
for (const entry of response.data) {
36+
// Match any of the requested version's ids,
37+
// as well as any ids that do not have a tag anymore, i.e. are fully unused.
38+
const { tags } = entry.metadata.container;
39+
const matchedTags = tags.filter((tag) => versions.delete(tag));
40+
if (tags.length === 0 || matchedTags.length !== 0) {
41+
ids.add(entry.id);
42+
}
43+
}
44+
page += 1;
45+
}
46+
return ids;
47+
};
48+
49+
module.exports = {
50+
removePackageVersions,
51+
};

.github/scripts/wait_for_service.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
MAX_RETRY_COUNT=10
4+
SERVICE_NAME="$1"
5+
6+
if [ ! -n "$SERVICE_NAME" ]; then
7+
echo "Usage: wait_for_container.sh <service_name>"
8+
exit 1
9+
fi
10+
11+
for i in $(seq 1 $MAX_RETRY_COUNT); do
12+
if [ "$(docker inspect -f '{{.State.Health.Status}}' "swissgeol-viewer-app-$SERVICE_NAME-1")" == "healthy" ]; then
13+
echo "Service $SERVICE_NAME is healthy!"
14+
exit 0
15+
else
16+
echo "Waiting for $SERVICE_NAME to be healthy... (attempt $i of $MAX_RETRY_COUNT)"
17+
sleep 10
18+
fi
19+
done
20+
21+
echo "Service $SERVICE_NAME did not become healthy in time."
22+
exit 1

0 commit comments

Comments
 (0)