From 037cac3794940a504cfccc446230cf8662183ad6 Mon Sep 17 00:00:00 2001 From: Zach Sanson <47839859+WibblyGhost@users.noreply.github.com> Date: Sun, 11 Sep 2022 17:13:19 +1200 Subject: [PATCH] Fix GitLab CI for Docker (#7) --- .github/workflows/docker-publish.yml | 93 ---------------- .github/workflows/docker-publish.yml.disabled | 79 ++++++++++++++ .../{pylint.yml => pylint.yml.disabled} | 16 +-- .github/workflows/workflow.yml | 102 ++++++++++++++++++ .gitignore | 1 + README.md | 1 + requirements-test.txt | 4 + 7 files changed, 197 insertions(+), 99 deletions(-) delete mode 100644 .github/workflows/docker-publish.yml create mode 100644 .github/workflows/docker-publish.yml.disabled rename .github/workflows/{pylint.yml => pylint.yml.disabled} (77%) create mode 100644 .github/workflows/workflow.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml deleted file mode 100644 index f28dcfa..0000000 --- a/.github/workflows/docker-publish.yml +++ /dev/null @@ -1,93 +0,0 @@ -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. -# https://github.com/marketplace/actions/build-and-push-docker-images - -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 - # 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@v3 - - # 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@7e0881f8fe90b25e305bbf0309761e9314607e25 - with: - cosign-release: 'v1.9.0' - - - # Workaround: https://github.com/docker/build-push-action/issues/461 - - name: Setup Docker buildx - uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf - - # 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@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c - 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@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 - 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@ac9327eae2b366085ac7f6a2d02df8aa8ead720a - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - file: solar-logger.dockerfile - - # 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: - COSIGN_EXPERIMENTAL: "true" - # This step uses the identity token to provision an ephemeral certificate - # against the sigstore community Fulcio instance. - run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.build-and-push.outputs.digest }} diff --git a/.github/workflows/docker-publish.yml.disabled b/.github/workflows/docker-publish.yml.disabled new file mode 100644 index 0000000..37c32fc --- /dev/null +++ b/.github/workflows/docker-publish.yml.disabled @@ -0,0 +1,79 @@ +name: Docker + +on: + push: + branches: [ "main" ] + tags: [ 'v*.*.*' ] + paths: + - '**.dockerfile' + - '**.py' + - '**.ps1' + - '**.yml' + pull_request: + branches: [ "main" ] + paths: + - '**.dockerfile' + - '**.py' + - '**.ps1' + - '**.yml' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set outputs + id: vars + run: | + echo "::set-output name=image_path::${IMAGE_NAME,,}" + [ ${{ github.event_name }} == 'pull_request' ] && echo "::set-output name=tag_name::$(git rev-parse --short HEAD)" || echo "::set-output name=tag_name::latest" + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + 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@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ steps.vars.outputs.image_path }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + # Build and push Docker image with Buildx + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ steps.vars.outputs.image_path }}:${{ steps.vars.outputs.tag_name }} + labels: ${{ steps.meta.outputs.labels }} + file: solar-logger.dockerfile diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml.disabled similarity index 77% rename from .github/workflows/pylint.yml rename to .github/workflows/pylint.yml.disabled index abbd682..a676a24 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml.disabled @@ -1,6 +1,10 @@ -name: Pylint +name: PyLint + +on: + push: + changes: + - '**.py' -on: [push] jobs: build: @@ -10,17 +14,17 @@ jobs: python-version: ["3.10"] steps: - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v3 with: python-version: ${{ matrix.python-version }} + - name: Install dependencies run: | python -m pip install --upgrade pip - pip install pylint - pip install -r requirements.txt - pip install -r requirements-test.txt + pip install -r requirements.txt -r requirements-test.txt + - name: Analysing the code with pylint run: | pylint $(git ls-files '*.py') - \ No newline at end of file diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml new file mode 100644 index 0000000..9b7ab35 --- /dev/null +++ b/.github/workflows/workflow.yml @@ -0,0 +1,102 @@ +name: Docker + +on: [push] + +# Unstable +# on: +# push: +# branches: [ "main" ] +# tags: [ 'v*.*.*' ] +# pull_request: +# branches: [ "main" ] +# paths: +# - '**.dockerfile' +# - '**.py' +# - '**.ps1' +# - '**.yml' + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + steps: + - uses: actions/checkout@v3 + + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt -r requirements-test.txt + + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') + + + build: + runs-on: ubuntu-latest + needs: lint + + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set outputs + id: vars + run: | + echo "::set-output name=image_path::${IMAGE_NAME,,}" + [ ${{ github.event_name }} == 'pull_request' ] && echo "::set-output name=tag_name::$(git rev-parse --short HEAD)" || echo "::set-output name=tag_name::latest" + + - name: Setup Docker buildx + uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf + + - name: Log into registry ${{ env.REGISTRY }} + uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c + 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@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ steps.vars.outputs.image_path }} + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + # Build and push Docker image with Buildx + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a + with: + context: . + push: true + tags: ${{ env.REGISTRY }}/${{ steps.vars.outputs.image_path }}:${{ steps.vars.outputs.tag_name }} + labels: ${{ steps.meta.outputs.labels }} + file: solar-logger.dockerfile diff --git a/.gitignore b/.gitignore index 0ce1cfe..7de1153 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ __pycache__/ .idea/ .vscode/ venv/ +*.venv/ *.py[cod] # Secret files diff --git a/README.md b/README.md index 8223891..fc05fab 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # Solar Logger + ![slice3](https://user-images.githubusercontent.com/47839859/161478218-66dbca5d-5277-479e-8144-1c017c92fbd3.png) [![Pylint](https://github.com/WibblyGhost/solar_logger/actions/workflows/pylint.yml/badge.svg)](https://github.com/WibblyGhost/solar_logger/actions/workflows/pylint.yml) diff --git a/requirements-test.txt b/requirements-test.txt index 154e605..f6b982f 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,3 +1,7 @@ +# Formatting +pylint +black + faker pytest pytest-coverage