|
1 | 1 | name: Docker Build and Trivy Scan |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - branches: |
6 | | - - '**' |
7 | | - |
8 | 4 | workflow_call: |
9 | 5 | inputs: |
10 | 6 | DOCKER_PATH_CONTEXT: |
|
13 | 9 | DOCKER_BUILD_DOCKERFILE: |
14 | 10 | required: true |
15 | 11 | type: string |
16 | | - DOCKER_LOAD_BOOL: |
17 | | - required: true |
18 | | - type: boolean |
19 | 12 | DOCKER_TAGS: |
20 | 13 | required: true |
21 | 14 | type: string |
| 15 | + DOCKER_LOAD_BOOL: |
| 16 | + required: false |
| 17 | + type: boolean |
| 18 | + default: false |
| 19 | + DOCKER_PUSH_BOOL: |
| 20 | + required: false |
| 21 | + type: boolean |
| 22 | + default: false |
22 | 23 |
|
23 | 24 | jobs: |
24 | 25 | build-and-scan: |
25 | 26 | runs-on: ubuntu-latest |
26 | | - env: |
27 | | - DOCKER_PATH_CONTEXT: . |
28 | | - DOCKER_BUILD_DOCKERFILE: Dockerfile |
29 | | - DOCKER_LOAD_BOOL: true |
30 | | - DOCKER_TAGS: sample-python-app:${{ github.sha }} |
31 | 27 | steps: |
32 | 28 | - name: Checkout repository |
33 | | - uses: actions/checkout@v4 |
| 29 | + uses: actions/checkout@v6 |
34 | 30 | - name: Set up QEMU |
35 | 31 | uses: docker/setup-qemu-action@v3 |
36 | 32 | - name: Set up Docker Buildx |
37 | 33 | uses: docker/setup-buildx-action@v3 |
38 | 34 | - name: Login to DockerHub |
39 | | - if: github.event_name == 'workflow_call' |
40 | 35 | uses: docker/login-action@v3 |
41 | 36 | with: |
42 | | - username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 37 | + username: ${{ vars.DOCKERHUB_USERNAME }} |
43 | 38 | password: ${{ secrets.DOCKERHUB_TOKEN }} |
44 | 39 | - name: Build (and maybe push) Docker image |
45 | 40 | uses: docker/build-push-action@v6 |
46 | 41 | with: |
47 | | - context: ${{ github.event_name == 'workflow_call' && inputs.DOCKER_PATH_CONTEXT || env.DOCKER_PATH_CONTEXT }} |
48 | | - file: ${{ github.event_name == 'workflow_call' && inputs.DOCKER_BUILD_DOCKERFILE || env.DOCKER_BUILD_DOCKERFILE }} |
49 | | - load: ${{ github.event_name != 'workflow_call' }} |
50 | | - push: ${{ github.event_name == 'workflow_call' }} |
51 | | - tags: ${{ github.event_name == 'workflow_call' && inputs.DOCKER_TAGS || env.DOCKER_TAGS }} |
52 | | - - name: Run Trivy vulnerability scanner |
| 42 | + context: ${{ inputs.DOCKER_PATH_CONTEXT }} |
| 43 | + file: ${{ inputs.DOCKER_BUILD_DOCKERFILE}} |
| 44 | + load: ${{ inputs.DOCKER_LOAD_BOOL }} |
| 45 | + push: ${{ inputs.DOCKER_PUSH_BOOL }} |
| 46 | + tags: ${{ inputs.DOCKER_TAGS }} |
| 47 | + - name: Run Trivy vulnerability scanner (remote) |
53 | 48 | uses: aquasecurity/trivy-action@0.33.1 |
54 | 49 | with: |
55 | | - image-ref: ${{ inputs.DOCKER_TAGS || env.DOCKER_TAGS }} |
| 50 | + image-ref: docker.io/${{ inputs.DOCKER_TAGS }} |
56 | 51 | format: 'table' |
57 | 52 | exit-code: '1' |
58 | 53 | ignore-unfixed: true |
|
0 commit comments