-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Pedro Martín <pedromarting3@gmail.com>
- Loading branch information
1 parent
5d41c6a
commit b739b51
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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 }} | ||
|
||
WORKING_DIRECTORY: ./api | ||
|
||
# Container Registries | ||
PROWLERCLOUD_DOCKERHUB_REPOSITORY: prowlercloud | ||
PROWLERCLOUD_DOCKERHUB_IMAGE: prowler-api | ||
|
||
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 |