From 6c40c0590247d92779766c0f846ba15fb350c97c Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Fri, 11 Aug 2023 17:55:50 -0400 Subject: [PATCH 1/2] Add containerization --- .dockerignore | 8 ++++ .github/workflows/container_build.yml | 61 +++++++++++++++++++++++++++ Dockerfile | 19 +++++++++ 3 files changed, 88 insertions(+) create mode 100644 .dockerignore create mode 100644 .github/workflows/container_build.yml create mode 100644 Dockerfile diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..90222ac --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Exclude everything but the listed exceptions. +* +!.git +!LICENSE +!pyproject.toml +!README.md +!relay +!setup.* diff --git a/.github/workflows/container_build.yml b/.github/workflows/container_build.yml new file mode 100644 index 0000000..f2d32b6 --- /dev/null +++ b/.github/workflows/container_build.yml @@ -0,0 +1,61 @@ +name: Create and publish a Docker image + +# Configure this workflow to run every time a change is pushed to a branch +# whose name starts with `release/` or any time a tag is created; this workflow +# is also run any time a GitHub release is created or updated ("unpublish" and +# deletions do not cause it to run). +on: + push: + branches: ['release/**'] + tags: ['*'] + release: + types: [created, edited, prereleased, published, released] + +# Set up the container image specification to be `quay.io/pbench/file-relay`. +env: + REGISTRY: quay.io + ORGANIZATION: pbench + IMAGE_NAME: file-relay + +jobs: + build-and-push-image: + runs-on: ubuntu-latest + + # Set the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_ROBOT_TOKEN }} + + # Extract metadata from the Git reference and the GitHub event. + # Subsequent steps can reference the values via `steps.meta.outputs.`. + # The `images` value provides the name for the container image which is + # used in tags and labels. + - name: Extract metadata (tags, labels) from Git for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ env.IMAGE_NAME }} + + # Build the container image based on the Dockerfile and the rest of the + # files found in the root of the Git checkout. If the build succeeds, + # the image is pushed to the registry indicated by the tags. + - name: Build and push Docker image + uses: docker/build-push-action@v4 + with: + context: . + file: Dockerfile + network: host + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa9114f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +FROM python:3.9 +LABEL org.opencontainers.image.authors="Pbench Maintainers " + +WORKDIR /var/tmp + +RUN python3 -m pip install --upgrade pip + +# Since we install the relay file in/from /src, we seem to need to include it +# in the PYTHONPATH. +# FIXME: how do we get this to install conventionally so we don't need this definition? +ENV PYTHONPATH=/src/file-relay/relay/ + +ENTRYPOINT ["relay"] + +# Copy the files from the context area to a source directory; install the +# dependencies; then install the app. +COPY . /src/file-relay +RUN python3 -m pip install -r /src/file-relay/relay/requirements.txt +RUN python3 -m pip install /src/file-relay From 2d0654d9a35aa53ea5474d4b6eac226b408db3d2 Mon Sep 17 00:00:00 2001 From: Webb Scales Date: Wed, 30 Aug 2023 13:15:27 -0400 Subject: [PATCH 2/2] Remove the PYTHONPATH definition, and, post-install, the sources --- .dockerignore | 2 +- Dockerfile | 17 ++++++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.dockerignore b/.dockerignore index 90222ac..3a114ac 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,5 +4,5 @@ !LICENSE !pyproject.toml !README.md -!relay +!src !setup.* diff --git a/Dockerfile b/Dockerfile index fa9114f..9b25715 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,19 +1,14 @@ FROM python:3.9 LABEL org.opencontainers.image.authors="Pbench Maintainers " +ENTRYPOINT ["relay"] WORKDIR /var/tmp -RUN python3 -m pip install --upgrade pip - -# Since we install the relay file in/from /src, we seem to need to include it -# in the PYTHONPATH. -# FIXME: how do we get this to install conventionally so we don't need this definition? -ENV PYTHONPATH=/src/file-relay/relay/ - -ENTRYPOINT ["relay"] +# Make sure the packaging and installation tools are up to date. +RUN python3 -m pip install --upgrade pip setuptools wheel # Copy the files from the context area to a source directory; install the -# dependencies; then install the app. +# dependencies and the app; and remove the sources. COPY . /src/file-relay -RUN python3 -m pip install -r /src/file-relay/relay/requirements.txt -RUN python3 -m pip install /src/file-relay +RUN python3 -m pip install -r /src/file-relay/src/requirements.txt /src/file-relay +RUN rm -rf /src/file-relay