mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-24 21:11:53 +00:00
99 lines
2.8 KiB
YAML
99 lines
2.8 KiB
YAML
name: API - Build and Push containers
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- "master"
|
|
paths:
|
|
- "api/**"
|
|
- ".github/workflows/api-build-lint-push-containers.yml"
|
|
|
|
# Uncomment the code below to test this action on PRs
|
|
# pull_request:
|
|
# branches:
|
|
# - "master"
|
|
# paths:
|
|
# - "api/**"
|
|
# - ".github/workflows/api-build-lint-push-containers.yml"
|
|
|
|
release:
|
|
types: [published]
|
|
|
|
env:
|
|
# Tags
|
|
LATEST_TAG: latest
|
|
RELEASE_TAG: ${{ github.event.release.tag_name }}
|
|
STABLE_TAG: stable
|
|
|
|
WORKING_DIRECTORY: ./api
|
|
|
|
# Container Registries
|
|
PROWLERCLOUD_DOCKERHUB_REPOSITORY: prowlercloud
|
|
PROWLERCLOUD_DOCKERHUB_IMAGE: prowler-api
|
|
|
|
jobs:
|
|
repository-check:
|
|
name: Repository check
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
is_repo: ${{ steps.repository_check.outputs.is_repo }}
|
|
steps:
|
|
- name: Repository check
|
|
id: repository_check
|
|
working-directory: /tmp
|
|
run: |
|
|
if [[ ${{ github.repository }} == "prowler-cloud/prowler" ]]
|
|
then
|
|
echo "is_repo=true" >> "${GITHUB_OUTPUT}"
|
|
else
|
|
echo "This action only runs for prowler-cloud/prowler"
|
|
echo "is_repo=false" >> "${GITHUB_OUTPUT}"
|
|
fi
|
|
|
|
# Build Prowler OSS container
|
|
container-build-push:
|
|
needs: repository-check
|
|
if: needs.repository-check.outputs.is_repo == 'true'
|
|
runs-on: ubuntu-latest
|
|
defaults:
|
|
run:
|
|
working-directory: ${{ env.WORKING_DIRECTORY }}
|
|
|
|
steps:
|
|
- 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 }}
|
|
${{ env.PROWLERCLOUD_DOCKERHUB_REPOSITORY }}/${{ env.PROWLERCLOUD_DOCKERHUB_IMAGE }}:${{ env.STABLE_TAG }}
|
|
cache-from: type=gha
|
|
cache-to: type=gha,mode=max
|