Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom docker buildargs #28

Merged
merged 9 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
extra_docker_envs: |
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this one is called extra_docker_envs and described as docker_buildargs?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍 I forget to update it, in first place

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
extra_docker_envs: |
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
79 changes: 54 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,58 @@ 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:
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);

const versionInput = core.getIntput('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 (frontend) {
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 +126,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 }}
51 changes: 39 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,42 @@ 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:
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);

const versionInput = core.getIntput('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 +102,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 }}