diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 5531a7a..e017484 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -11,6 +11,9 @@ jobs: build-and-push: runs-on: ubuntu-latest steps: + - name: Checkout Repository + uses: actions/checkout@v4 + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 diff --git a/Dockerfile b/Dockerfile index fcb71fd..48cb81f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,23 @@ -FROM openjdk:21-jdk +FROM adoptopenjdk/openjdk11 +# Set the working directory WORKDIR /app -# Define an argument to accept the Photon version +# Install necessary tools +RUN apt-get update && apt-get install -y wget pbzip2 curl + +# Define build argument for Photon version ARG PHOTON_VERSION -# Download the Photon JAR file for the specified version -RUN curl -L -o photon.jar https://github.com/komoot/photon/releases/download/${PHOTON_VERSION}/photon-${PHOTON_VERSION}.jar +# Download the specified Photon release +RUN wget https://github.com/komoot/photon/releases/download/${PHOTON_VERSION}/photon-${PHOTON_VERSION}.jar -O photon.jar + +# Copy the startup script +COPY start-photon.sh /app/start-photon.sh +RUN chmod +x /app/start-photon.sh +# Expose the default Photon port EXPOSE 2322 -# Run the Photon server -CMD ["java", "-jar", "photon.jar"] +# Set the command to run the startup script +CMD ["/app/start-photon.sh"] diff --git a/start-photon.sh b/start-photon.sh new file mode 100644 index 0000000..eaaf614 --- /dev/null +++ b/start-photon.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +set -e + +DATA_DIR="/app/photon_data" +INDEX_URL="https://download1.graphhopper.com/public/photon-db-latest.tar.bz2" + +# Function to download and extract the index +download_and_extract_index() { + echo "Downloading and extracting the Photon index..." + mkdir -p "$DATA_DIR" + wget -O - "$INDEX_URL" | pbzip2 -cd | tar x -C "$DATA_DIR" + echo "Index downloaded and extracted successfully." +} + +# Check if the index already exists +if [ ! -d "$DATA_DIR" ] || [ -z "$(ls -A "$DATA_DIR")" ]; then + download_and_extract_index +else + echo "Photon index already exists. Skipping download." +fi + +# Start Photon +echo "Starting Photon..." +exec java -jar photon.jar -data-dir "$DATA_DIR"