Skip to content

Commit 8b85587

Browse files
authored
feat: custom docker buildargs (#28)
* feat: add custom envs in build-frontend action * feat: add custom envs for middleware * refactor: use one resolve step * docs: update README.md * fix: README.md * fix: bugs * fix: bug * ci: fix reading build-args * fix: string encoding
1 parent b0df365 commit 8b85587

File tree

3 files changed

+108
-42
lines changed

3 files changed

+108
-42
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ With those four you can easily compose the deployment script for your needs.
1515
### build-frontend
1616

1717
```yaml
18-
uses: vuestorefront/storefront-deployment/build-frontend@v4.4.0
18+
uses: vuestorefront/storefront-deployment/build-frontend@v4.5.0
1919
with:
2020
project_name: ${{ secrets.PROJECT_NAME }}
2121
cloud_username: ${{ secrets.CLOUD_USERNAME }}
@@ -28,6 +28,9 @@ with:
2828
npm_registry: 'https://registrynpm.storefrontcloud.io'
2929
version: '2.3.0'
3030
image_provider: 'ipx'
31+
docker_buildargs: |
32+
EXTRA_ENV_FOR_DOCKERFILE=somevalue-hardcoded
33+
ANOTHER_EXTRA_ENV=${{ secrets.SOME_VALUE }}
3134
```
3235
3336
**Input Parameters:**
@@ -43,13 +46,14 @@ with:
4346
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
4447
- `version`: Version that will be used for docker image tag. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used
4548
- `image_provider`: Select image provider for Nuxt Image. Optional field. Only for Nuxt.
49+
- `docker_buildargs`: Multi-line input field, for passing in the additional build args. Optional field.
4650

4751
Any environment variables needed by an application is needed to be set in the Alokai Console.
4852

4953
### build-middleware
5054

5155
```yaml
52-
uses: vuestorefront/storefront-deployment/build-middleware@v4.4.0
56+
uses: vuestorefront/storefront-deployment/build-middleware@v4.5.0
5357
with:
5458
project_name: ${{ secrets.PROJECT_NAME }}
5559
cloud_username: ${{ secrets.CLOUD_USERNAME }}
@@ -60,6 +64,9 @@ with:
6064
docker_registry_url: 'registry.vuestorefront.cloud'
6165
npm_registry: 'https://registrynpm.storefrontcloud.io'
6266
version: 2.3.0
67+
docker_buildargs: |
68+
EXTRA_ENV_FOR_DOCKERFILE=somevalue-hardcoded
69+
ANOTHER_EXTRA_ENV=${{ secrets.SOME_VALUE }}
6370
```
6471

6572
**Input Parameters:**
@@ -73,11 +80,12 @@ with:
7380
- `docker_registry_url`: URL to the Docker image registry. Optional field. Defaults to `registry.vuestorefront.cloud`.
7481
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
7582
- `version`: Version that will be used for docker image tag. Example: 2.3.0, 3.1.0-rc.1. If not passed, github.sha will be used
83+
- `docker_buildargs`: Multi-line input field, for passing in the additional build args. Optional field.
7684

7785
### build-stripe-ct
7886

7987
```yaml
80-
uses: vuestorefront/storefront-deployment/build-stripe-ct@v4.4.0
88+
uses: vuestorefront/storefront-deployment/build-stripe-ct@v4.5.0
8189
with:
8290
project_name: ${{ secrets.PROJECT_NAME }}
8391
cloud_username: ${{ secrets.CLOUD_USERNAME }}
@@ -107,7 +115,7 @@ with:
107115
### deploy
108116

109117
```yaml
110-
uses: vuestorefront/storefront-deployment/deploy@v4.4.0
118+
uses: vuestorefront/storefront-deployment/deploy@v4.5.0
111119
with:
112120
project_name: ${{ secrets.PROJECT_NAME }}
113121
cloud_username: ${{ secrets.CLOUD_USERNAME }}
@@ -133,7 +141,7 @@ with:
133141
### deploy/stripe-ct
134142

135143
```yaml
136-
uses: vuestorefront/storefront-deployment/deploy/stripe-ct@v4.4.0
144+
uses: vuestorefront/storefront-deployment/deploy/stripe-ct@v4.5.0
137145
with:
138146
project_name: ${{ secrets.PROJECT_NAME }}
139147
cloud_username: ${{ secrets.CLOUD_USERNAME }}

build-frontend/action.yml

Lines changed: 55 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ inputs:
3838
description: 'Image provider (only for Nuxt)'
3939
required: false
4040
default: 'ipx'
41+
docker_buildargs:
42+
description: 'List of additional ENVs that should be passed at Docker image build-time'
43+
required: false
4144
runs:
4245
using: 'composite'
4346
steps:
@@ -52,27 +55,59 @@ runs:
5255
username: ${{ inputs.cloud_username }}
5356
password: ${{ inputs.cloud_password }}
5457

55-
- name: Resolve values of the versions, docker ref & dockerfile path
58+
- name: Resolve docker buildargs
5659
id: resolve
57-
shell: bash
58-
run: |
59-
# Set the version of the app based on user input or use git commit hash
60-
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
61-
# Set the reference address for app in docker registry
62-
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
63-
# Set the path to the Dockerfile base on selected frontend framework
64-
if [[ $FRONTEND == "next" ]]; then
65-
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
66-
elif [[ $FRONTEND == "nextjs" ]]; then
67-
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
68-
elif [[ $FRONTEND == "nuxt" ]]; then
69-
echo "path=.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
70-
else
71-
echo "Error: Unsupported FRONTEND value. Valid options are 'next' or 'nuxt'."
72-
exit 1
73-
fi
60+
uses: actions/github-script@v7
7461
env:
75-
FRONTEND: ${{ inputs.frontend }}
62+
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
63+
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
64+
INPUT_NPM_USER: ${{ inputs.npm_user }}
65+
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
66+
INPUT_IMAGE_PROVIDER: ${{ inputs.image_provider }}
67+
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
68+
INPUT_FRONTEND: ${{ inputs.frontend }}
69+
INPUT_VERSION: ${{ inputs.version }}
70+
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
71+
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
72+
with:
73+
result-encoding: string
74+
script: |
75+
const base = {
76+
'NPM_EMAIL': core.getInput('npm_email'),
77+
'NPM_PASS': core.getInput('npm_pass'),
78+
'NPM_USER': core.getInput('npm_user'),
79+
'NPM_REGISTRY': core.getInput('npm_registry'),
80+
'NUXT_IMAGE_PROVIDER': core.getInput('image_provider'),
81+
};
82+
83+
const transformedBaseArgs = Object.entries(base)
84+
.map(([key, value]) => `${key}=${value}`);
85+
86+
const extraArgs = core.getMultilineInput('docker_buildargs', { required: false });
87+
const mergedArgs = [
88+
...transformedBaseArgs,
89+
...extraArgs,
90+
];
91+
92+
core.setOutput('docker_args', mergedArgs.join('\n'));
93+
94+
const versionInput = core.getInput('version');
95+
core.setOutput('version', versionInput || context.sha);
96+
97+
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
98+
99+
const frontendInput = core.getInput('frontend');
100+
101+
switch (frontendInput) {
102+
case "next":
103+
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend');
104+
break;
105+
case "nuxt":
106+
core.setOutput('path', '.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend');
107+
break;
108+
default:
109+
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend')
110+
}
76111
77112
- name: Check for existing image
78113
id: check-existing-image
@@ -92,9 +127,4 @@ runs:
92127
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront:${{ steps.resolve.outputs.version }}
93128
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache"
94129
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache,mode=max"
95-
build-args: |
96-
NPM_EMAIL=${{ inputs.npm_email }}
97-
NPM_PASS=${{ inputs.npm_pass }}
98-
NPM_USER=${{ inputs.npm_user }}
99-
NPM_REGISTRY=${{ inputs.npm_registry }}
100-
NUXT_IMAGE_PROVIDER=${{ inputs.image_provider }}
130+
build-args: ${{ steps.resolve.outputs.docker_args }}

build-middleware/action.yml

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ inputs:
3030
version:
3131
description: 'Version of the app'
3232
required: false
33+
docker_buildargs:
34+
description: 'List of additional ENVs that should be passed at Docker image build-time'
35+
required: false
3336
runs:
3437
using: "composite"
3538
steps:
@@ -44,14 +47,43 @@ runs:
4447
username: ${{ inputs.cloud_username }}
4548
password: ${{ inputs.cloud_password }}
4649

47-
- name: Resolve values of the versions, docker ref & dockerfile path
50+
- name: Resolve docker buildargs
4851
id: resolve
49-
shell: bash
50-
run: |
51-
# Set the version of the app based on user input or use git commit hash
52-
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
53-
# Set the reference address for app in docker registry
54-
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
52+
uses: actions/github-script@v7
53+
env:
54+
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
55+
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
56+
INPUT_NPM_USER: ${{ inputs.npm_user }}
57+
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
58+
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
59+
INPUT_VERSION: ${{ inputs.version }}
60+
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
61+
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
62+
with:
63+
result-encoding: string
64+
script: |
65+
const base = {
66+
'NPM_EMAIL': core.getInput('npm_email'),
67+
'NPM_PASS': core.getInput('npm_pass'),
68+
'NPM_USER': core.getInput('npm_user'),
69+
'NPM_REGISTRY': core.getInput('npm_registry'),
70+
};
71+
72+
const transformedBaseArgs = Object.entries(base)
73+
.map(([key, value]) => `${key}=${value}`);
74+
75+
const extraBuildArgs = core.getMultilineInput('docker_buildargs', { required: false });
76+
const mergedBuildArgs = [
77+
...transformedBaseArgs,
78+
...extraBuildArgs,
79+
];
80+
81+
core.setOutput('docker_args', mergedBuildArgs.join('\n'));
82+
83+
const versionInput = core.getInput('version');
84+
core.setOutput('version', versionInput || context.sha);
85+
86+
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
5587
5688
- name: Check for existing image
5789
id: check-existing-image
@@ -71,8 +103,4 @@ runs:
71103
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:${{ steps.resolve.outputs.version }}
72104
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache"
73105
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache,mode=max"
74-
build-args: |
75-
NPM_EMAIL=${{ inputs.npm_email }}
76-
NPM_PASS=${{ inputs.npm_pass }}
77-
NPM_USER=${{ inputs.npm_user }}
78-
NPM_REGISTRY=${{ inputs.npm_registry }}
106+
build-args: ${{ steps.resolve.outputs.docker_args }}

0 commit comments

Comments
 (0)