From e9360ee79bfda8baf01e363e32edd855e8597e2d Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 12:36:55 +0100 Subject: [PATCH 1/7] add dockerfile and build shell script --- Dockerfile | 24 ++++++++++++++++++++++++ build-image.sh | 2 ++ 2 files changed, 26 insertions(+) create mode 100644 Dockerfile create mode 100644 build-image.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..dc8569f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +FROM python:3.11-slim +#LABEL authors="farrag" + +WORKDIR /src + +# Copy files in local working directory to docker working directory +COPY . . + +# Update the package source list, update system packages +RUN apt-get update && apt-get upgrade -y \ + # And install additional dependencies: + && apt-get install -y curl git + +# install poetry (/usr/local/bin/poetry) +RUN pip install poetry + +# Install Poetry dependencies without creating poetry environment +## Packages are installed in "/usr/local/lib/python3.9/site-packages/" when the environment is not created, +## which corresponds to the local installation of Python "/usr/local/bin/python" in the base Docker image +RUN poetry config virtualenvs.create false +RUN poetry install +RUN apt-get clean autoclean + +#ENTRYPOINT ["top", "-b"] diff --git a/build-image.sh b/build-image.sh new file mode 100644 index 00000000..4eb5c9f1 --- /dev/null +++ b/build-image.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker build . --file Dockerfile --tag decoimpact:latest From 6a1281ac804fe242cba1440004338941dae2d0cf Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 15:24:16 +0100 Subject: [PATCH 2/7] clean dockerfile --- Dockerfile | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index dc8569f2..b3fc5494 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,24 +1,19 @@ FROM python:3.11-slim -#LABEL authors="farrag" -WORKDIR /src +WORKDIR /decoimpact # Copy files in local working directory to docker working directory COPY . . # Update the package source list, update system packages -RUN apt-get update && apt-get upgrade -y \ - # And install additional dependencies: - && apt-get install -y curl git +RUN apt-get update && apt-get upgrade -y # install poetry (/usr/local/bin/poetry) RUN pip install poetry # Install Poetry dependencies without creating poetry environment -## Packages are installed in "/usr/local/lib/python3.9/site-packages/" when the environment is not created, +## Packages are installed in "/usr/local/lib/python/site-packages/" when the environment is not created, ## which corresponds to the local installation of Python "/usr/local/bin/python" in the base Docker image RUN poetry config virtualenvs.create false RUN poetry install RUN apt-get clean autoclean - -#ENTRYPOINT ["top", "-b"] From 9886618964e20f71de9e57f2ba1a64f24a19dcb9 Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 16:32:58 +0100 Subject: [PATCH 3/7] link the package to the repo --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index b3fc5494..458c551b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.11-slim +LABEL org.opencontainers.image.source="https://github.com/Deltares/D-EcoImpact" + WORKDIR /decoimpact # Copy files in local working directory to docker working directory From db1c64e0f2f1b92e64f026e73e45650f2e89eb8e Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 16:35:28 +0100 Subject: [PATCH 4/7] add github container registry to the image tag --- build-image.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/build-image.sh b/build-image.sh index 4eb5c9f1..21dc6478 100644 --- a/build-image.sh +++ b/build-image.sh @@ -1,2 +1,10 @@ #!/bin/bash -docker build . --file Dockerfile --tag decoimpact:latest +export IMAGE_ID="decoimpact" +export VERSION="latest" +export ARTIFACT_REGISTRY_URL="ghcr.io/deltares" +export TAG="${ARTIFACT_REGISTRY_URL}/${IMAGE_ID}:${VERSION}" + +docker build . --file Dockerfile --tag "${TAG}" + +## Pushes image to Artifact Registry +docker push "${TAG}" From 009a78d3df8497cd7793cba5d695b14974e61043 Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 16:35:57 +0100 Subject: [PATCH 5/7] add instructions of the image in readme --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index f4deb12c..95c19dfa 100644 --- a/README.md +++ b/README.md @@ -146,3 +146,23 @@ To add an acceptance test: +## Docker image + +### Build +To build the docker image, run the following command in the root of the project: + +```sh + +$ build-image.sh + +``` + +### Pull + +To pull the docker image from the docker hub, run the following command: + +```sh + +$ docker pull ghcr.io/deltares/d-ecoimpact:latest + +``` From bd1da0b15a30c0b3a0a360cf1e041889380045be Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Wed, 14 Feb 2024 16:37:16 +0100 Subject: [PATCH 6/7] correct typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95c19dfa..aa451e2b 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ To build the docker image, run the following command in the root of the project: ```sh -$ build-image.sh +$ ./build-image.sh ``` From f57ff9e8d6f620517dd70256062eb3e2bda763ec Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Tue, 20 Feb 2024 14:26:00 +0100 Subject: [PATCH 7/7] add authentication instructions --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index aa451e2b..c8289a7a 100644 --- a/README.md +++ b/README.md @@ -166,3 +166,12 @@ To pull the docker image from the docker hub, run the following command: $ docker pull ghcr.io/deltares/d-ecoimpact:latest ``` + +### Authentication with GitHub Container Registry +Before building your Docker image, ensure you're authenticated with GHCR to allow pulling private images. Use the +docker login command with your GitHub username and a Personal Access Token (PAT) that has the appropriate scopes +(read:packages at a minimum). + +```bash +echo "YOUR_PERSONAL_ACCESS_TOKEN" | docker login ghcr.io -u YOUR_GITHUB_USERNAME --password-stdin +```