From 001483038b17b70afcf6b041fbc462cc15b61ec4 Mon Sep 17 00:00:00 2001 From: Pepe Fagoaga Date: Thu, 12 Dec 2024 19:10:44 +0100 Subject: [PATCH] chore(gha): build and push OSS UI (#6168) (cherry picked from commit 554491a6425b865b5f73dc13cbe3a560964415ed) --- .../ui-build-lint-push-containers.yml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .github/workflows/ui-build-lint-push-containers.yml diff --git a/.github/workflows/ui-build-lint-push-containers.yml b/.github/workflows/ui-build-lint-push-containers.yml new file mode 100644 index 00000000000..41c0a11017c --- /dev/null +++ b/.github/workflows/ui-build-lint-push-containers.yml @@ -0,0 +1,81 @@ +name: UI - Build and Push containers + +on: + push: + branches: + - "master" + paths: + - "ui/**" + - ".github/workflows/ui-build-lint-push-containers.yml" + + # Uncomment the below code to test this action on PRs + # pull_request: + # branches: + # - "master" + # paths: + # - "ui/**" + # - ".github/workflows/ui-build-lint-push-containers.yml" + + release: + types: [published] + +env: + # Tags + LATEST_TAG: latest + RELEASE_TAG: ${{ github.event.release.tag_name }} + + WORKING_DIRECTORY: ./ui + + # Container Registries + PROWLERCLOUD_DOCKERHUB_REPOSITORY: prowlercloud + PROWLERCLOUD_DOCKERHUB_IMAGE: prowler-ui + +jobs: + # Build Prowler OSS container + container-build-push: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ${{ env.WORKING_DIRECTORY }} + + steps: + - name: Repository check + working-directory: /tmp + run: | + [[ ${{ github.repository }} != "prowler-cloud/prowler" ]] && echo "This action only runs for prowler-cloud/prowler"; exit 0 + + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push container image (latest) + # Comment the following line for testing + if: github.event_name == 'push' + uses: docker/build-push-action@v6 + with: + context: ${{ env.WORKING_DIRECTORY }} + # Set push: false for testing + push: true + tags: | + ${{ env.PROWLERCLOUD_DOCKERHUB_REPOSITORY }}/${{ env.PROWLERCLOUD_DOCKERHUB_IMAGE }}:${{ env.LATEST_TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Build and push container image (release) + if: github.event_name == 'release' + uses: docker/build-push-action@v6 + with: + context: ${{ env.WORKING_DIRECTORY }} + push: true + tags: | + ${{ env.PROWLERCLOUD_DOCKERHUB_REPOSITORY }}/${{ env.PROWLERCLOUD_DOCKERHUB_IMAGE }}:${{ env.RELEASE_TAG }} + cache-from: type=gha + cache-to: type=gha,mode=max