Skip to content

Commit

Permalink
🔨 Add custom entrypoint script to copy initial data
Browse files Browse the repository at this point in the history
  • Loading branch information
agmangas committed Mar 17, 2024
1 parent 53a37eb commit e8d8e59
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM ubuntu:24.04 as build

RUN apt-get update -y && apt-get install -y \
build-essential \
git \
curl

RUN apt-get update -y && apt-get install -y build-essential git curl
WORKDIR /opt
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d
COPY . .
ENV GEOSERVER_DATA_DIR /opt/geoserver/data_dir
RUN GEOSERVER_DATA_DIR="${GEOSERVER_DATA_DIR}" ./bin/task download-geoserver-data
ENV INIT_DATA_DIR /opt/init_data
RUN GEOSERVER_DATA_DIR="${INIT_DATA_DIR}" ./bin/task download-geoserver-data

FROM kartoza/geoserver:2.24.2 as geoserver
COPY --from=build /opt/geoserver/data_dir /opt/geoserver/data_dir
RUN apt-get update -y && apt-get install --no-install-recommends -y rsync
ENV INIT_DATA_DIR /opt/init_data
ENV GEOSERVER_DATA_DIR /opt/geoserver/data_dir
COPY --from=build ${INIT_DATA_DIR} ${INIT_DATA_DIR}
COPY custom-entrypoint.sh /scripts/custom-entrypoint.sh
ENTRYPOINT ["/bin/bash", "/scripts/custom-entrypoint.sh"]
22 changes: 22 additions & 0 deletions custom-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -x

: ${INIT_DATA_DIR:?} || exit 1
: ${GEOSERVER_DATA_DIR:?} || exit 1

# Ensure the GeoServer data directory exists
mkdir -p ${GEOSERVER_DATA_DIR}

echo "Copying initial data from ${INIT_DATA_DIR} to ${GEOSERVER_DATA_DIR}"

# The -a option stands for "archive", which means it preserves the files' attributes
# The -v option stands for "verbose"
# The --ignore-existing option tells rsync to skip updating files that already exist in the destination directory
rsync -av --ignore-existing ${INIT_DATA_DIR}/ ${GEOSERVER_DATA_DIR}/

set +x

# Delegate to the original entrypoint
# https://github.com/kartoza/docker-geoserver/blob/develop/scripts/entrypoint.sh
exec /scripts/entrypoint.sh "$@"

0 comments on commit e8d8e59

Please sign in to comment.