Skip to content

Commit 7249559

Browse files
feat: allow build-arg for docker build (#94)
1 parent 220279d commit 7249559

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

.github/workflows/deploy-docker.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ name: Build & Deploy Docker
33
on:
44
workflow_call:
55
inputs:
6+
build-args:
7+
description: "Docker build arguments (multiline format: KEY1=value1\nKEY2=value2)"
8+
required: false
9+
default: ""
10+
type: string
611
dockerfile:
712
description: "Path to Dockerfile"
813
default: "Dockerfile"
@@ -69,6 +74,7 @@ jobs:
6974
needs: get-tag
7075
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
7176
with:
77+
build-args: ${{ inputs.build-args }}
7278
dockerfile: ${{ inputs.dockerfile }}
7379
image-name: ${{ inputs.image_name }}
7480
image-tag: ${{ needs.get-tag.outputs.tag }}

.github/workflows/docker-build.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Build, Test and Push Docker Image
33
on:
44
workflow_call:
55
inputs:
6+
build-args:
7+
description: "Docker build arguments (multiline format: KEY1=value1\nKEY2=value2)"
8+
default: ""
9+
type: string
610
image-name:
711
description: "Name of Docker Image"
812
type: string
@@ -73,6 +77,7 @@ jobs:
7377
- name: Build Docker Image
7478
uses: docker/build-push-action@v6
7579
with:
80+
build-args: ${{ inputs.build-args }}
7681
context: ${{ inputs.context }}
7782
file: ${{ inputs.dockerfile }}
7883
platforms: ${{ inputs.platforms }}
@@ -82,7 +87,15 @@ jobs:
8287
- name: Build Docker Image as Tarball
8388
if: ${{ inputs.security-scan }}
8489
run: |
85-
docker build -t ${{ inputs.image-name }}:${{ inputs.image-tag }} -f ${{ inputs.dockerfile }} ${{ inputs.context }}
90+
BUILD_ARGS=""
91+
if [ -n "${{ inputs.build-args }}" ]; then
92+
while IFS= read -r line; do
93+
if [ -n "$line" ]; then
94+
BUILD_ARGS="$BUILD_ARGS --build-arg $line"
95+
fi
96+
done <<< "${{ inputs.build-args }}"
97+
fi
98+
docker build $BUILD_ARGS -t ${{ inputs.image-name }}:${{ inputs.image-tag }} -f ${{ inputs.dockerfile }} ${{ inputs.context }}
8699
docker save -o vuln-image.tar ${{ inputs.image-name }}:${{ inputs.image-tag }}
87100
88101
- name: Run Trivy vulnerability scanner

deploy-docker/README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This reusable GitHub Actions workflow automates the process of building a Docker
1212

1313
| **Input** | **Description** | **Required** | **Default** |
1414
|------------------|-----------------------------------------------------|--------------|-----------------|
15+
| **build-args** | Docker build arguments (multiline format: `KEY1=value1\nKEY2=value2`). | No | `""` |
1516
| **dockerfile** | Path to Dockerfile. | No | `Dockerfile` |
1617
| **image_name** | Full image name (e.g. org/my-api). | Yes | - |
1718
| **image_tag** | Optional tag override (defaults to pushed Git tag). | No | - |
@@ -47,6 +48,7 @@ This reusable GitHub Actions workflow automates the process of building a Docker
4748
- **Depends On**: `get-tag`
4849
- **Uses**: The docker-build workflow from the same repository.
4950
- **Inputs**:
51+
- Build arguments (optional)
5052
- Dockerfile path
5153
- Image name and tag
5254
- Push configuration (set to true)
@@ -65,10 +67,10 @@ This reusable GitHub Actions workflow automates the process of building a Docker
6567

6668
## How to Use This Reusable Workflow 🔄
6769

68-
1. **Save the Workflow File**
70+
1. **Save the Workflow File**
6971
This workflow is already saved as `.github/workflows/deploy-docker.yml` in the repository. 💾
7072

71-
2. **Call the Reusable Workflow**
73+
2. **Call the Reusable Workflow**
7274
In another workflow file (e.g., triggered by a release), invoke this reusable workflow like so:
7375

7476
```yaml
@@ -81,6 +83,9 @@ This reusable GitHub Actions workflow automates the process of building a Docker
8183
deploy:
8284
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/deploy-docker.yml@main
8385
with:
86+
build-args: |
87+
BUILD_VERSION=1.0.0
88+
NODE_ENV=production
8489
dockerfile: 'path/to/Dockerfile'
8590
image_name: 'your-org/your-app'
8691
remote_host: '[email protected]'
@@ -91,7 +96,7 @@ This reusable GitHub Actions workflow automates the process of building a Docker
9196
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
9297
```
9398
94-
3. **Configure Secrets**
99+
3. **Configure Secrets**
95100
Ensure that the following secrets are added to your repository's settings:
96101
- `DOCKERHUB_USERNAME`: Your DockerHub username
97102
- `DOCKERHUB_PASSWORD`: Your DockerHub password or access token

docker-build/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ This reusable GitHub Actions workflow automates the process of building and push
1919

2020
| Name | Description | Required | Default |
2121
| ----------------- | ---------------------------------------------------------------------------------- | -------- | --------------------------- |
22+
| `build-args` | Docker build arguments (multiline format: `KEY1=value1\nKEY2=value2`) | No | `""` |
23+
| `context` | Path to Docker Build Context | No | `"."` |
24+
| `dockerfile` | Path to the Dockerfile to build (e.g., './Dockerfile', './docker/Dockerfile') | No | `"Dockerfile"` |
25+
| `hadolint` | Enable Hadolint | No | `true` |
2226
| `image-name` | Name of Docker Image (e.g., 'myimage', 'myorg/myimage') | true | - |
2327
| `image-tag` | Tag to apply to the built image (e.g., 'latest', 'v1.2.3') | No | `"latest"` |
24-
| `dockerfile` | Path to the Dockerfile to build (e.g., './Dockerfile', './docker/Dockerfile') | No | `"Dockerfile"` |
25-
| `context` | Path to Docker Build Context | No | `"."` |
2628
| `platforms` | Indicates which platforms the image should be built for | No | `"linux/amd64,linux/arm64"` |
27-
| `registry` | Docker Registry | No | `"docker.io"` |
2829
| `push` | Push Docker Image to Registry | No | `false` |
29-
| `security-scan` | Enable Trivy Security Scan | No | `true` |
30+
| `registry` | Docker Registry | No | `"docker.io"` |
3031
| `security-report` | Security Report Mode (`"sarif"` \| `"comment"`; ignored if `security-scan: false`) | No | `"sarif"` |
31-
| `hadolint` | Enable Hadolint | No | `true` |
32+
| `security-scan` | Enable Trivy Security Scan | No | `true` |
3233

3334
## 🔐 Secrets
3435

@@ -62,6 +63,9 @@ jobs:
6263
with:
6364
image-name: "username/my-image"
6465
dockerfile: "Dockerfile"
66+
build-args: |
67+
BUILD_VERSION=1.0.0
68+
NODE_ENV=production
6569
secrets:
6670
username: ${{ secrets.DOCKERHUB_USERNAME }}
6771
password: ${{ secrets.DOCKERHUB_PAT }}

0 commit comments

Comments
 (0)