Skip to content

Commit 5938150

Browse files
committed
add the github action
1 parent 5951a29 commit 5938150

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

.github/workflows/build.yml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "main", '[0-9]+\.[0-9]+\.[0-9]+', '[0-9]+\.[0-9]+\.[x]' ]
6+
7+
env:
8+
DOCKER_REPO: ${{ vars.DOCKER_REPO }}
9+
10+
jobs:
11+
build_image:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Validate build conditions
15+
env:
16+
NIGHTLY_MASTER_VERSION: ${{ vars.NIGHTLY_MASTER_VERSION }}
17+
NIGHTLY_STABLE_VERSION: ${{ vars.NIGHTLY_STABLE_VERSION }}
18+
NIGHTLY_MAINT_VERSION: ${{ vars.NIGHTLY_MAINT_VERSION }}
19+
STABLE_VERSION: ${{ vars.STABLE_VERSION }}
20+
MAINT_VERSION: ${{ vars.MAINT_VERSION }}
21+
run: |
22+
buildable_status=1
23+
versions=("$NIGHTLY_MASTER_VERSION" "$NIGHTLY_STABLE_VERSION" "$NIGHTLY_MAINT_VERSION" "$STABLE_VERSION" "$MAINT_VERSION")
24+
# We will proceed with the build only if the branch name is valid and supported by our repo-level vars.
25+
for version in "${versions[@]}"; do
26+
for single_version in $version; do
27+
if [[ "$GITHUB_REF_NAME" == "$single_version" ]]; then
28+
# Valid version
29+
buildable_status=0
30+
break;
31+
fi
32+
done
33+
done
34+
exit $buildable_status
35+
36+
- name: Initialise the cache for the plugin dependencies
37+
id: plugincache
38+
uses: actions/cache@v4
39+
with:
40+
path: ./resources/geoserver-plugins/
41+
key: ${{ runner.os }}-build-${{ github.ref_name }}
42+
43+
- name: Download the dependencies (plugins)
44+
if: steps.plugincache.outputs.cache-hit != 'true'
45+
env:
46+
PLUG_IN_LIST: "monitor control-flow libjpeg-turbo"
47+
run: |
48+
for version in $NIGHTLY_MASTER_VERSION; do
49+
if [[ "$GITHUB_REF_NAME" == $version ]]; then
50+
PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE + 1)-SNAPSHOT"
51+
break
52+
fi
53+
done
54+
if [ -z $PLUG_IN_VERSION ]; then
55+
for version in $NIGHTLY_STABLE_VERSION; do
56+
if [[ "$GITHUB_REF_NAME" == $version ]]; then
57+
PLUG_IN_VERSION="2.$MIDDLE_STABLE-SNAPSHOT"
58+
break
59+
fi
60+
done
61+
fi
62+
if [ -z $PLUG_IN_VERSION ]; then
63+
for version in $NIGHTLY_MAINT_VERSION; do
64+
if [[ "$GITHUB_REF_NAME" == $version ]]; then
65+
PLUG_IN_VERSION="2.$(expr $MIDDLE_STABLE - 1)-SNAPSHOT"
66+
break
67+
fi
68+
done
69+
fi
70+
71+
if [ -z $PLUG_IN_VERSION ]; then
72+
for version in $STABLE_VERSION $MAINT_VERSION; do
73+
if [[ "$GITHUB_REF_NAME" == $version ]]; then
74+
PLUG_IN_VERSION="$version"
75+
break
76+
fi
77+
done
78+
fi
79+
80+
mkdir -p ./resources/geoserver-plugins
81+
for PLUG_IN_NAME in $PLUG_IN_LIST; do
82+
URL="https://build.geoserver.org/geoserver/$GITHUB_REF_NAME/ext-latest/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip"
83+
curl -C - -k -o ./resources/geoserver-plugins/geoserver-$PLUG_IN_VERSION-$PLUG_IN_NAME-plugin.zip $URL
84+
done
85+
86+
- uses: actions/checkout@v4
87+
- name: Build the geoserver image
88+
run: |
89+
WAR_FILE="https://build.geoserver.org/geoserver/$GITHUB_REF_NAME/geoserver-$GITHUB_REF_NAME-latest-war.zip"
90+
docker build \
91+
--build-arg GEOSERVER_WEBAPP_SRC="$WAR_FILE" \
92+
--build-arg PLUG_IN_PATHS="./resources/geoserver-plugins" \
93+
-f "$DOCKERFILE_PATH" \
94+
-t "${DOCKER_REPO}:$GITHUB_REF_NAME" .
95+
rm -rf ./resources/geoserver-plugins/*
96+
97+
- name: Login to docker hub
98+
uses: docker/[email protected]
99+
with:
100+
username: ${{ secrets.REGISTRY_USERNAME }}
101+
password: ${{ secrets.REGISTRY_PASSWORD }}
102+
103+
- name: Push docker image
104+
run: docker push "${DOCKER_REPO}:$GITHUB_REF_NAME"
105+
106+
test:
107+
runs-on: ubuntu-latest
108+
needs: build_image
109+
timeout-minutes: 10
110+
steps:
111+
- name: Run the tests
112+
run: docker run --rm -i "${DOCKER_REPO}:$GITHUB_REF_NAME" /docker/tests/run_tests.sh

0 commit comments

Comments
 (0)