From 8c5145f756f01bec98b5a5ec1c5aed39e0443c2b Mon Sep 17 00:00:00 2001 From: Naved Ansari Date: Fri, 16 Feb 2024 10:06:47 -0500 Subject: [PATCH] Add dockerfile and github workflow to build a container image I am using the slim python image because it's much smaller than the standard image. --- .github/workflows/build.yaml | 68 ++++++++++++++++++++++++++++++++++++ Dockerfile | 9 +++++ 2 files changed, 77 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 Dockerfile diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..c758d0e --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,68 @@ +name: Build + +# 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: + push: + branches: [main] + # Publish semver tags as releases. + tags: ['v*.*.*'] + pull_request: + branches: [main] + +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 + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + # 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@v2 + 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@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern=v{{version}} + type=semver,pattern=v{{major}}.{{minor}} + type=semver,pattern=v{{major}} + type=ref,event=branch + type=ref,event=pr + type=sha + + # 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 + uses: docker/build-push-action@v4 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..c2ff164 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM python:3.11.8-slim + +WORKDIR /app +COPY requirements.txt ./ +RUN pip install -r requirements.txt + +COPY openshift_metrics/ /app/openshift_metrics + +CMD ["python", "openshift_metrics/openshift_prometheus_metrics.py", "--upload-to-s3"]