Skip to content

Commit

Permalink
feat: custom docker buildargs (#28)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
grixu authored Oct 22, 2024
1 parent b0df365 commit 8b85587
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 42 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ With those four you can easily compose the deployment script for your needs.
### build-frontend

```yaml
uses: vuestorefront/storefront-deployment/build-frontend@v4.4.0
uses: vuestorefront/storefront-deployment/build-frontend@v4.5.0
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
Expand All @@ -28,6 +28,9 @@ with:
npm_registry: 'https://registrynpm.storefrontcloud.io'
version: '2.3.0'
image_provider: 'ipx'
docker_buildargs: |
EXTRA_ENV_FOR_DOCKERFILE=somevalue-hardcoded
ANOTHER_EXTRA_ENV=${{ secrets.SOME_VALUE }}
```
**Input Parameters:**
Expand All @@ -43,13 +46,14 @@ with:
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
- `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
- `image_provider`: Select image provider for Nuxt Image. Optional field. Only for Nuxt.
- `docker_buildargs`: Multi-line input field, for passing in the additional build args. Optional field.

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

### build-middleware

```yaml
uses: vuestorefront/storefront-deployment/build-middleware@v4.4.0
uses: vuestorefront/storefront-deployment/build-middleware@v4.5.0
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
Expand All @@ -60,6 +64,9 @@ with:
docker_registry_url: 'registry.vuestorefront.cloud'
npm_registry: 'https://registrynpm.storefrontcloud.io'
version: 2.3.0
docker_buildargs: |
EXTRA_ENV_FOR_DOCKERFILE=somevalue-hardcoded
ANOTHER_EXTRA_ENV=${{ secrets.SOME_VALUE }}
```

**Input Parameters:**
Expand All @@ -73,11 +80,12 @@ with:
- `docker_registry_url`: URL to the Docker image registry. Optional field. Defaults to `registry.vuestorefront.cloud`.
- `npm_registry`: URL to the private NPM registry. Optional field. Defaults to `https://registrynpm.storefrontcloud.io`.
- `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
- `docker_buildargs`: Multi-line input field, for passing in the additional build args. Optional field.

### build-stripe-ct

```yaml
uses: vuestorefront/storefront-deployment/build-stripe-ct@v4.4.0
uses: vuestorefront/storefront-deployment/build-stripe-ct@v4.5.0
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
Expand Down Expand Up @@ -107,7 +115,7 @@ with:
### deploy

```yaml
uses: vuestorefront/storefront-deployment/deploy@v4.4.0
uses: vuestorefront/storefront-deployment/deploy@v4.5.0
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
Expand All @@ -133,7 +141,7 @@ with:
### deploy/stripe-ct

```yaml
uses: vuestorefront/storefront-deployment/deploy/stripe-ct@v4.4.0
uses: vuestorefront/storefront-deployment/deploy/stripe-ct@v4.5.0
with:
project_name: ${{ secrets.PROJECT_NAME }}
cloud_username: ${{ secrets.CLOUD_USERNAME }}
Expand Down
80 changes: 55 additions & 25 deletions build-frontend/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ inputs:
description: 'Image provider (only for Nuxt)'
required: false
default: 'ipx'
docker_buildargs:
description: 'List of additional ENVs that should be passed at Docker image build-time'
required: false
runs:
using: 'composite'
steps:
Expand All @@ -52,27 +55,59 @@ runs:
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}

- name: Resolve values of the versions, docker ref & dockerfile path
- name: Resolve docker buildargs
id: resolve
shell: bash
run: |
# Set the version of the app based on user input or use git commit hash
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
# Set the reference address for app in docker registry
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
# Set the path to the Dockerfile base on selected frontend framework
if [[ $FRONTEND == "next" ]]; then
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
elif [[ $FRONTEND == "nextjs" ]]; then
echo "path=.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
elif [[ $FRONTEND == "nuxt" ]]; then
echo "path=.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend" >> $GITHUB_OUTPUT
else
echo "Error: Unsupported FRONTEND value. Valid options are 'next' or 'nuxt'."
exit 1
fi
uses: actions/github-script@v7
env:
FRONTEND: ${{ inputs.frontend }}
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
INPUT_NPM_USER: ${{ inputs.npm_user }}
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
INPUT_IMAGE_PROVIDER: ${{ inputs.image_provider }}
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
INPUT_FRONTEND: ${{ inputs.frontend }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
with:
result-encoding: string
script: |
const base = {
'NPM_EMAIL': core.getInput('npm_email'),
'NPM_PASS': core.getInput('npm_pass'),
'NPM_USER': core.getInput('npm_user'),
'NPM_REGISTRY': core.getInput('npm_registry'),
'NUXT_IMAGE_PROVIDER': core.getInput('image_provider'),
};
const transformedBaseArgs = Object.entries(base)
.map(([key, value]) => `${key}=${value}`);
const extraArgs = core.getMultilineInput('docker_buildargs', { required: false });
const mergedArgs = [
...transformedBaseArgs,
...extraArgs,
];
core.setOutput('docker_args', mergedArgs.join('\n'));
const versionInput = core.getInput('version');
core.setOutput('version', versionInput || context.sha);
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
const frontendInput = core.getInput('frontend');
switch (frontendInput) {
case "next":
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend');
break;
case "nuxt":
core.setOutput('path', '.vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend');
break;
default:
core.setOutput('path', '.vuestorefrontcloud/docker/nextjs/Dockerfile-frontend')
}
- name: Check for existing image
id: check-existing-image
Expand All @@ -92,9 +127,4 @@ runs:
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront:${{ steps.resolve.outputs.version }}
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache"
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront:buildcache,mode=max"
build-args: |
NPM_EMAIL=${{ inputs.npm_email }}
NPM_PASS=${{ inputs.npm_pass }}
NPM_USER=${{ inputs.npm_user }}
NPM_REGISTRY=${{ inputs.npm_registry }}
NUXT_IMAGE_PROVIDER=${{ inputs.image_provider }}
build-args: ${{ steps.resolve.outputs.docker_args }}
52 changes: 40 additions & 12 deletions build-middleware/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ inputs:
version:
description: 'Version of the app'
required: false
docker_buildargs:
description: 'List of additional ENVs that should be passed at Docker image build-time'
required: false
runs:
using: "composite"
steps:
Expand All @@ -44,14 +47,43 @@ runs:
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}

- name: Resolve values of the versions, docker ref & dockerfile path
- name: Resolve docker buildargs
id: resolve
shell: bash
run: |
# Set the version of the app based on user input or use git commit hash
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
# Set the reference address for app in docker registry
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
uses: actions/github-script@v7
env:
INPUT_NPM_EMAIL: ${{ inputs.npm_email }}
INPUT_NPM_PASS: ${{ inputs.npm_pass }}
INPUT_NPM_USER: ${{ inputs.npm_user }}
INPUT_NPM_REGISTRY: ${{ inputs.npm_registry }}
INPUT_DOCKER_BUILDARGS: ${{ inputs.docker_buildargs }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_DOCKER_REGISTRY_URL: ${{ inputs.docker_registry_url }}
INPUT_PROJECT_NAME: ${{ inputs.project_name }}
with:
result-encoding: string
script: |
const base = {
'NPM_EMAIL': core.getInput('npm_email'),
'NPM_PASS': core.getInput('npm_pass'),
'NPM_USER': core.getInput('npm_user'),
'NPM_REGISTRY': core.getInput('npm_registry'),
};
const transformedBaseArgs = Object.entries(base)
.map(([key, value]) => `${key}=${value}`);
const extraBuildArgs = core.getMultilineInput('docker_buildargs', { required: false });
const mergedBuildArgs = [
...transformedBaseArgs,
...extraBuildArgs,
];
core.setOutput('docker_args', mergedBuildArgs.join('\n'));
const versionInput = core.getInput('version');
core.setOutput('version', versionInput || context.sha);
core.setOutput('ref', `${core.getInput('docker_registry_url')}/${core.getInput('project_name')}-storefrontcloud-io`);
- name: Check for existing image
id: check-existing-image
Expand All @@ -71,8 +103,4 @@ runs:
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:${{ steps.resolve.outputs.version }}
cache-from: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache"
cache-to: "type=registry,ref=${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:buildcache,mode=max"
build-args: |
NPM_EMAIL=${{ inputs.npm_email }}
NPM_PASS=${{ inputs.npm_pass }}
NPM_USER=${{ inputs.npm_user }}
NPM_REGISTRY=${{ inputs.npm_registry }}
build-args: ${{ steps.resolve.outputs.docker_args }}

0 comments on commit 8b85587

Please sign in to comment.