diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 00000000..b3778357 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,99 @@ +name: Docker + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +on: + # schedule: + # - cron: '35 8 * * *' + push: + branches: [ "develop" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "develop" ] + workflow_dispatch: + +env: + # Use docker.io for Docker Hub if empty + REGISTRY: ghcr.io + # github.repository as / + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: ./containers + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST} \ No newline at end of file diff --git a/containers/Dockerfile b/containers/Dockerfile new file mode 100644 index 00000000..cd1af348 --- /dev/null +++ b/containers/Dockerfile @@ -0,0 +1,55 @@ +# Use an official Ubuntu as a parent image +FROM ubuntu:24.04 + +# Set environment variables +ENV DEBIAN_FRONTEND=noninteractive + +ARG env_path + +# Install dependencies +RUN apt-get update && apt-get install -y \ + openjdk-17-jdk \ + maven \ + python3 \ + python3-pip \ + wget \ + unzip \ + git \ + && apt-get clean + +# Install Miniconda +RUN wget --quiet https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh && \ + /bin/bash ~/miniconda.sh -b -p /opt/conda && \ + rm ~/miniconda.sh + +# Set path to conda +ENV PATH /opt/conda/bin:$PATH + +# Install Osmosis +RUN wget --quiet https://github.com/openstreetmap/osmosis/releases/download/0.48.3/osmosis-0.48.3.zip -O /tmp/osmosis.zip && \ + unzip /tmp/osmosis.zip -d /opt/osmosis && \ + rm /tmp/osmosis.zip && \ + ln -s /opt/osmosis/bin/osmosis /usr/local/bin/osmosis + +# Verify installations +RUN java -version && \ + mvn -version && \ + python3 --version && \ + conda --version && \ + which osmosis + +# Copy the environment.yml file into the container if env_path is set (else will create an empty directory) +COPY ${env_path} /tmp/environment.yml.tmp + +# Check if env_path is set, if not use from the repo +RUN if [ -z "$env_path" ]; then \ + cp ./environment.yml /tmp/environment.yml; \ + else \ + mv /tmp/environment.yml.tmp /tmp/environment.yml; \ + fi + +# Create the conda environment +RUN conda env create -f /tmp/environment.yml -n eqasim + +# Activate the environment +RUN echo "source activate eqasim" > ~/.bashrc diff --git a/containers/apptainer.def b/containers/apptainer.def new file mode 100644 index 00000000..9fa7d1ec --- /dev/null +++ b/containers/apptainer.def @@ -0,0 +1,8 @@ +Bootstrap: docker +From: ghcr.io/eqasim-org/ile-de-france:latest + +%environment + source /opt/conda/bin/activate eqasim + +%runscript + exec python -m synpp "$@" \ No newline at end of file diff --git a/docs/containers.md b/docs/containers.md new file mode 100644 index 00000000..5a2ef6e8 --- /dev/null +++ b/docs/containers.md @@ -0,0 +1,36 @@ +# Containers + +Containers for running the Eqasim pipeline are located in the `containers` folder + +## Docker container + +To build the container : +`docker build -t eqasim .` + +This will pull the conda environment from the current repo. + +To build using your own environment.yml file : +`docker build --build-arg env_path=/path/to/my/environment.yml -t eqasim .` + +To run the pipeline : +```bash +docker run --rm -it \ + --mount type=bind,src=/path/to/eqasim-ile-de-france,target=/usr/local/eqasim \ + --mount type=bind,src=/path/to/eqasim-data,target=/usr/local/eqasim-data \ + ghcr.io/eqasim-org/ile-de-france:latest /bin/bash -l -c "cd /usr/local/eqasim && python -m synpp"` +``` + +where : + +- `/path/to/eqasim-ile-de-france` is the path of the [eqasim pipline](https://github.com/eqasim-org/ile-de-france) on your *host* machine. +- `/usr/local/eqasim` is going to be the path of the eqasim pipeline inside the container. +- `/path/to/eqasim-data` is the path of the data (bdtopo, hts, sirene, etc.) folder on your *host* machine. +- `/usr/local/eqasim-data` is the path of the data folder in the container. **This is the path you need to put in your `congif.yml` file** + +## Apptainer + +To build the container : +`apptainer -v -d build eqasim.sif apptainer.def` + +To run the pipeline : +`apptainer run eqasim.sif`