Fixed typo (#24) #17
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
name: Verify c4p tools and push to DockerHub | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
env: | |
PROJECT_NAME: containers4pentesters | |
TOOL_DIR: tools | |
jobs: | |
pre-configure: | |
runs-on: ubuntu-latest | |
if: "!contains(github.event.head_commit.message, '[SKIP CI]')" | |
outputs: | |
tools_matrix: ${{ steps.set-matrix.outputs.tools_matrix }} | |
steps: | |
- name: Checkout to repository | |
uses: actions/checkout@v3 | |
- name: Set tools matrix data | |
id: set-matrix | |
run: echo "tools_matrix=$(jq -c . < ./tools.json)" >> $GITHUB_OUTPUT | |
test-tools: | |
name: Test c4p and its tools | |
needs: pre-configure | |
runs-on: ubuntu-20.04 | |
env: | |
DOCKER_NETWORK_TYPE: none | |
DEBIAN_FRONTEND: noninteractive | |
strategy: | |
matrix: ${{ fromJson(needs.pre-configure.outputs.tools_matrix) }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Clean and reorder the packages in the system | |
run: | | |
df -h | |
echo "Removing large packages" | |
sudo apt-get remove -y '^dotnet-.*' || true | |
sudo apt-get remove -y '^llvm-.*' || true | |
sudo apt-get remove -y 'php.*' || true | |
sudo apt-get remove -y azure-cli google-cloud-sdk hhvm google-chrome-stable firefox powershell mono-devel || true | |
sudo apt-get autoremove -y | |
sudo apt-get clean | |
df -h | |
- name: Test - check if proper files exist | |
uses: andstor/file-existence-action@v3 | |
with: | |
fail: true | |
files: | | |
${{ env.TOOL_DIR }}/${{ matrix.tool_name }}/README.md, | |
${{ env.TOOL_DIR }}/${{ matrix.tool_name }}/Dockerfile, | |
${{ env.TOOL_DIR }}/${{ matrix.tool_name }}/test.sh | |
- name: Test - list available tools | |
run: | | |
$GITHUB_WORKSPACE/c4p.sh --list | |
- name: Test - install unexisting tool | |
run: | | |
echo $( $GITHUB_WORKSPACE/c4p.sh --log-level 4 --tool unexisting || true ) | tee console.txt; \ | |
[ -s $GITHUB_WORKSPACE/console.txt ] && grep -q "unexisting" console.txt | |
- name: Test - logging to file and console | |
run: | | |
echo $( $GITHUB_WORKSPACE/c4p.sh --log-level 4 --log-file logs.txt --tool unexisting || true ) | tee console.txt; \ | |
[ -s $GITHUB_WORKSPACE/logs.txt ] && [ -s $GITHUB_WORKSPACE/console.txt ] | |
- name: Test - logging only to file | |
run: | | |
echo $( $GITHUB_WORKSPACE/c4p.sh --log-level 4 --log-file logs.txt --only-log-file --tool unexisting || true ) | tee console.txt; \ | |
[ -s $GITHUB_WORKSPACE/logs.txt ] && ! grep -q '[^[:space:]]' $GITHUB_WORKSPACE/console.txt | |
- name: Test - install given tool | |
run: | | |
$GITHUB_WORKSPACE/c4p.sh --fail --log-level 4 --log-file $GITHUB_WORKSPACE/c4p-logs.txt -t ${{ matrix.tool_name }} | |
build-and-push-docker-image: | |
name: Build Docker image and push to repositories | |
needs: [pre-configure, test-tools] | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: ${{ fromJson(needs.pre-configure.outputs.tools_matrix) }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.PROJECT_NAME }} | |
password: ${{ secrets.DOCKER_SECRET }} | |
- name: Extract metadata (tags, labels) for Docker image ${{ env.PROJECT_NAME }}/${{ matrix.changed-tools }} | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.PROJECT_NAME }}/${{ matrix.tool_name }} | |
tags: | | |
type=raw,value=latest | |
type=schedule | |
type=sha | |
- name: Build and push Docker image ${{ env.PROJECT_NAME }}/${{ matrix.tool_name }} | |
uses: docker/build-push-action@v5 | |
id: docker_build | |
with: | |
context: ${{ env.TOOL_DIR }}/${{ matrix.tool_name }} | |
file: ${{ env.TOOL_DIR }}/${{ matrix.tool_name }}/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Create a description for each image on Docker Hub | |
uses: peter-evans/dockerhub-description@v4 | |
with: | |
username: ${{ env.PROJECT_NAME }} | |
password: ${{ secrets.DOCKER_SECRET }} | |
repository: ${{ env.PROJECT_NAME }}/${{ matrix.tool_name }} | |
short-description: Containerized ${{ matrix.tool_name }} tool. Created by ${{ env.PROJECT_NAME }}. | |
readme-filepath: ${{ env.TOOL_DIR }}/${{ matrix.tool_name }}/README.md | |
- name: Image ${{ env.PROJECT_NAME }}/${{ matrix.tool_name }} digest | |
run: echo ${{ steps.docker_build.outputs.digest }} | |
after-build-and-push-notification: | |
name: Send notifications after the build and push | |
env: | |
IS_TELEGRAM_TOKEN_SET: ${{ secrets.TELEGRAM_TOKEN != '' }} | |
runs-on: ubuntu-latest | |
if: ${{ always() }} | |
needs: [build-and-push-docker-image, test-tools] | |
steps: | |
- name: Telegram notification | |
if: ${{ env.IS_TELEGRAM_TOKEN_SET == 'true' }} | |
uses: appleboy/telegram-action@master | |
with: | |
to: ${{ secrets.TELEGRAM_TO }} | |
token: ${{ secrets.TELEGRAM_TOKEN }} | |
format: markdown | |
message: | | |
*Workflow* `${{ github.workflow }}` *finished!* | |
*Info:* | |
- Job status: `${{ (job.status == 'success' && !contains(needs.*.result, 'failure')) && 'success' || 'failure' }}` | |
- Job started by: `${{ github.actor }}` | |
- Repository: [${{ github.repository }}](https://github.com/${{ github.repository }}) |