Skip to content

Commit ebcb059

Browse files
fix(docker-build): make image-tag and dockerfile optional
1 parent 29174e7 commit ebcb059

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

β€Ž.github/workflows/docker-build.ymlβ€Ž

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ name: Build, Test and Push Docker Image
33
on:
44
workflow_call:
55
inputs:
6-
dockerfile:
7-
description: 'Path to Dockerfile'
8-
default: 'Dockerfile'
9-
type: string
106
image-name:
11-
description: 'Name of Docker Image'
7+
description: "Name of Docker Image"
128
type: string
139
required: true
10+
dockerfile:
11+
description: "Path to Dockerfile"
12+
default: "Dockerfile"
13+
type: string
1414
image-tag:
15-
description: 'Tag of Docker Image'
15+
description: "Tag of Docker Image"
16+
default: "latest"
1617
type: string
17-
required: true
1818
security-scan:
19-
description: 'Enable Security Scan'
19+
description: "Enable Security Scan"
2020
default: true
2121
type: boolean
2222
security-report:
23-
description: 'Enable Security Report'
24-
default: 'sarif'
23+
description: "Enable Security Report"
24+
default: "sarif"
2525
type: string
2626
hadolint:
27-
description: 'Enable Hadolint'
27+
description: "Enable Hadolint"
2828
default: true
2929
type: boolean
3030
push:
31-
description: 'Push Docker Image to Registry'
31+
description: "Push Docker Image to Registry"
3232
default: false
3333
type: boolean
3434
context:
35-
description: 'Path to Docker Build Context'
36-
default: '.'
35+
description: "Path to Docker Build Context"
36+
default: "."
3737
type: string
3838
registry:
39-
description: 'Docker Registry'
40-
default: 'docker.io'
39+
description: "Docker Registry"
40+
default: "docker.io"
4141
type: string
4242
secrets:
4343
username:
@@ -88,10 +88,10 @@ jobs:
8888
uses: aquasecurity/[email protected]
8989
with:
9090
input: vuln-image.tar
91-
format: 'table'
91+
format: "table"
9292
ignore-unfixed: true
93-
vuln-type: 'os,library'
94-
severity: 'CRITICAL,HIGH'
93+
vuln-type: "os,library"
94+
severity: "CRITICAL,HIGH"
9595
hide-progress: true
9696
output: trivy.txt
9797

@@ -109,8 +109,8 @@ jobs:
109109
uses: peter-evans/find-comment@v3
110110
with:
111111
issue-number: ${{ github.event.pull_request.number }}
112-
comment-author: 'github-actions[bot]'
113-
body-includes: 'Trivy Security Scan Results'
112+
comment-author: "github-actions[bot]"
113+
body-includes: "Trivy Security Scan Results"
114114

115115
- name: Create or update Trivy comment
116116
if: github.event_name == 'pull_request' && inputs.security-scan && inputs.security-report == 'comment'
@@ -134,7 +134,7 @@ jobs:
134134
if: github.event_name == 'pull_request' && inputs.security-scan && inputs.security-report == 'sarif'
135135
uses: github/codeql-action/upload-sarif@v3
136136
with:
137-
sarif_file: 'trivy-results.sarif'
137+
sarif_file: "trivy-results.sarif"
138138

139139
- name: Run Hadolint Dockerfile linter
140140
id: hadolint
@@ -159,8 +159,8 @@ jobs:
159159
uses: peter-evans/find-comment@v3
160160
with:
161161
issue-number: ${{ github.event.pull_request.number }}
162-
comment-author: 'github-actions[bot]'
163-
body-includes: 'Hadolint Dockerfile Lint Results'
162+
comment-author: "github-actions[bot]"
163+
body-includes: "Hadolint Dockerfile Lint Results"
164164

165165
- name: Create or update Hadolint comment
166166
if: ${{ inputs.hadolint && steps.read_hadolint.outputs.report != '' }}

β€Ždocker-build/README.mdβ€Ž

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# 🐳 Docker Build Workflow
22

33
## πŸ” Overview
4+
45
This reusable GitHub Actions workflow automates the process of building and pushing Docker images to Docker Hub. It simplifies the Docker build process in your CI/CD pipeline by handling authentication, building, and tagging in a standardized way. Perfect for teams looking to streamline their containerization workflow with minimal configuration.
56

67
## ✨ Features
8+
79
- πŸ” Securely authenticates with Docker Hub using best practices
810
- πŸ—οΈ Builds optimized Docker images from a specified Dockerfile
911
- 🏷️ Intelligently tags and pushes images to Docker Hub
@@ -13,17 +15,18 @@ This reusable GitHub Actions workflow automates the process of building and push
1315

1416
## βš™οΈ Inputs
1517

16-
| Name | Description | Required | Default |
17-
|------|-------------|----------|---------|
18-
| `dockerfile` | Path to the Dockerfile to build (e.g., './Dockerfile', './docker/Dockerfile') | Yes | - |
19-
| `tag` | Tag to apply to the built image (e.g., 'myimage:latest', 'myorg/myimage:v1.2.3') | Yes | - |
18+
| Name | Description | Required | Default |
19+
| ------------ | -------------------------------------------------------------------------------- | -------- | -------------- |
20+
| `image-name` | Tag to apply to the built image (e.g., 'myimage:latest', 'myorg/myimage:v1.2.3') | true | - |
21+
| `image-tag` | Tag to apply to the built image (e.g., 'latest', 'v1.2.3') | No | `"latest"` |
22+
| `dockerfile` | Path to the Dockerfile to build (e.g., './Dockerfile', './docker/Dockerfile') | No | `"Dockerfile"` |
2023

2124
## πŸ” Secrets
2225

23-
| Name | Description | Required |
24-
|------|-------------|----------|
25-
| `dockerhub_username` | Username for Docker Hub authentication | Yes |
26-
| `dockerhub_pat` | Personal Access Token for Docker Hub authentication (with appropriate permissions) | Yes |
26+
| Name | Description | Required |
27+
| -------------------- | ---------------------------------------------------------------------------------- | -------- |
28+
| `dockerhub_username` | Username for Docker Hub authentication | Yes |
29+
| `dockerhub_pat` | Personal Access Token for Docker Hub authentication (with appropriate permissions) | Yes |
2730

2831
## πŸ’» Example Usage
2932

@@ -32,32 +35,33 @@ name: Build and Push Docker Image
3235

3336
on:
3437
push:
35-
branches: [ main ]
38+
branches: [main]
3639
# Also trigger on tag creation for release versioning
3740
tags:
38-
- 'v*.*.*'
41+
- "v*.*.*"
3942

4043
jobs:
4144
build:
4245
runs-on: ubuntu-latest
4346
steps:
4447
- uses: actions/checkout@v3
4548
with:
46-
fetch-depth: 0 # Fetch all history for proper versioning
49+
fetch-depth: 0 # Fetch all history for proper versioning
4750

4851
- name: Build and Push Docker Image
4952
uses: iExecBlockchainComputing/github-actions-workflows/[email protected]
5053
with:
51-
dockerfile: 'Dockerfile'
52-
tag: 'my-image:latest'
53-
secrets:
54+
image-name: "username/my-image"
55+
dockerfile: "Dockerfile"
56+
secrets:
5457
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
5558
dockerhub_pat: ${{ secrets.DOCKERHUB_PAT }}
5659
```
5760
5861
## πŸ” Advanced Usage
5962
6063
### Multi-Platform Build Example
64+
6165
```yaml
6266
name: Build Multi-Platform Docker Image
6367

@@ -80,21 +84,23 @@ jobs:
8084
- name: Build and Push Docker Image
8185
uses: iExecBlockchainComputing/github-actions-workflows/[email protected]
8286
with:
83-
dockerfile: 'Dockerfile'
84-
tag: 'myorg/myapp:${{ github.event.release.tag_name }}'
85-
secrets:
87+
dockerfile: "Dockerfile"
88+
tag: "myorg/myapp:${{ github.event.release.tag_name }}"
89+
secrets:
8690
dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }}
8791
dockerhub_pat: ${{ secrets.DOCKERHUB_PAT }}
8892
```
8993
9094
## πŸ“ Notes
95+
9196
- πŸ”’ Ensure your Docker Hub credentials are stored securely as GitHub Secrets
9297
- πŸ”„ The workflow will automatically handle the Docker build and push process
9398
- 🏷️ You can specify any valid Docker tag format in the `tag` input
9499
- πŸ“… Consider using dynamic tags based on git tags, commit SHAs, or dates
95100
- πŸ§ͺ For testing purposes, you can use the `--dry-run` flag in your own implementation
96101

97102
## πŸ› οΈ Troubleshooting
103+
98104
- If you encounter authentication issues, verify your Docker Hub credentials are correct and have appropriate permissions
99105
- For build failures, check your Dockerfile syntax and ensure all referenced files exist
100106
- Large images may take longer to push - consider optimizing your Dockerfile with multi-stage builds

0 commit comments

Comments
Β (0)