From b0149f4f95daea4dae961b2767f6c0b10ce23507 Mon Sep 17 00:00:00 2001 From: Tim de Pater Date: Thu, 16 Sep 2021 08:10:03 +0200 Subject: [PATCH] Migrate the Docker build process to GitHub Actions --- .github/workflows/deploy.yaml | 57 +++++++++++++++++++++++++++++++++++ docker-compose.test.yml | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/deploy.yaml diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 00000000..0f7d37d6 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,57 @@ +name: Test & build Docker image + +on: + push: + branches: [ master ] + pull_request: + +env: + IMAGE_NAME: trafex/wordpress + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Build image + run: |- + docker build -t $IMAGE_NAME . + docker tag $IMAGE_NAME:latest $IMAGE_NAME:${{ github.sha }} + + - name: Smoke test image + run: |- + docker-compose -f docker-compose.test.yml up -d wordpress + 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 }}:${{ github.sha }}' + 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' + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Push latest image + if: github.ref == 'refs/heads/master' && github.event_name == 'push' + run: |- + docker push $IMAGE_NAME:latest + + - name: Push tagged image + if: contains(github.ref, 'refs/tags/v') + run: |- + docker push $IMAGE_NAME:$GITHUB_TAG diff --git a/docker-compose.test.yml b/docker-compose.test.yml index 6f8aa534..d2558b1d 100644 --- a/docker-compose.test.yml +++ b/docker-compose.test.yml @@ -22,7 +22,7 @@ services: FS_METHOD: direct sut: - image: alpine:3.10 + image: alpine:3.13 depends_on: - wordpress command: /tmp/run_tests.sh