From c6492c6f16455a1f57e6848cdb6bd5e6fbf940a2 Mon Sep 17 00:00:00 2001 From: Webb Scales <7795764+webbnh@users.noreply.github.com> Date: Wed, 30 Aug 2023 14:53:01 -0400 Subject: [PATCH] Add a container image for the utility and build for it (#7) PBENCH-1258 --- .dockerignore | 8 ++++ .github/workflows/container_build.yml | 61 +++++++++++++++++++++++++++ Dockerfile | 14 ++++++ 3 files changed, 83 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..3a114ac --- /dev/null +++ b/.dockerignore @@ -0,0 +1,8 @@ +# Exclude everything but the listed exceptions. +* +!.git +!LICENSE +!pyproject.toml +!README.md +!src +!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..9b25715 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM python:3.9 +LABEL org.opencontainers.image.authors="Pbench Maintainers " + +ENTRYPOINT ["relay"] +WORKDIR /var/tmp + +# 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 and the app; and remove the sources. +COPY . /src/file-relay +RUN python3 -m pip install -r /src/file-relay/src/requirements.txt /src/file-relay +RUN rm -rf /src/file-relay