From e1675090ca5082732ca11d4b3df7b19bcbb1af64 Mon Sep 17 00:00:00 2001 From: hiddehs Date: Tue, 4 Oct 2022 09:07:19 +0200 Subject: [PATCH] Publish --- .github/workflows/build.yaml | 81 ----------------- .github/workflows/docker-publish.yml | 96 ++++++++++++++++++++ .github/workflows/dockerhub-description.yaml | 21 ----- Dockerfile | 2 +- 4 files changed, 97 insertions(+), 103 deletions(-) delete mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/docker-publish.yml delete mode 100644 .github/workflows/dockerhub-description.yaml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index 142a99137..000000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,81 +0,0 @@ -name: Test & build Docker image - -on: - push: - branches: [ master ] - tags: ['*'] - pull_request: - -env: - IMAGE_NAME: trafex/php-nginx - IMAGE_TAG: ${{ github.sha }} - DOCKER_BUILDKIT: 1 - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Build image - run: |- - docker build -t $IMAGE_NAME:$IMAGE_TAG . - - - name: Smoke test image - run: |- - docker-compose -f docker-compose.test.yml up -d app - sleep 2 - docker-compose -f docker-compose.test.yml run sut - - - name: Run Trivy vulnerability scanner - uses: aquasecurity/trivy-action@master - with: - image-ref: '${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}' - format: 'template' - template: '@/contrib/sarif.tpl' - output: 'trivy-results.sarif' - - - name: Upload Trivy scan results to GitHub Security tab - uses: github/codeql-action/upload-sarif@v1 - with: - sarif_file: 'trivy-results.sarif' - - - name: Login to Docker Hub - if: (github.ref == 'refs/heads/master' && github.event_name == 'push') || contains(github.ref, 'refs/tags/') - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build multi-arch image and push latest tag - if: github.ref == 'refs/heads/master' && github.event_name == 'push' - run: |- - docker buildx build \ - --cache-from=$IMAGE_NAME:latest \ - --push \ - -t $IMAGE_NAME:latest \ - --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ - . - - - name: Set tag in environment - if: contains(github.ref, 'refs/tags/') - run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - - - name: Build multi-arch image and push release tag - if: contains(github.ref, 'refs/tags/') - run: |- - docker buildx build \ - --cache-from=$IMAGE_NAME:latest \ - --push \ - -t $IMAGE_NAME:$RELEASE_VERSION \ - --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6 \ - . diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 000000000..29e9502ec --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,96 @@ +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. + +on: + schedule: + - cron: '15 16 * * *' + push: + branches: [ "master" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "master" ] + +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@f3c664df7af409cb4873aa5068053ba9d61a57b6 #v2.6.0 + with: + cosign-release: 'v1.11.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 }} + cache-from: type=gha + cache-to: type=gha,mode=max + + + # 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/dockerhub-description.yaml b/.github/workflows/dockerhub-description.yaml deleted file mode 100644 index fa153ad6b..000000000 --- a/.github/workflows/dockerhub-description.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Update Docker Hub Description -on: - push: - branches: - - master - paths: - - README.md - - .github/workflows/dockerhub-description.yml -jobs: - dockerHubDescription: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - repository: trafex/php-nginx - short-description: ${{ github.event.repository.description }} diff --git a/Dockerfile b/Dockerfile index 82ef2cd69..1e5647ae5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ ARG ALPINE_VERSION=3.16 FROM alpine:${ALPINE_VERSION} LABEL Maintainer="Tim de Pater " -LABEL Description="Lightweight container with Nginx 1.22 & PHP 8.1 based on Alpine Linux." +LABEL Description="Lightweight container with Nginx 1.22 & PHP 8.1 based on Alpine Linux. With Laravel support by @hidde.me" # Setup document root WORKDIR /var/www/html