Skip to content

Commit

Permalink
feat: add caching on docker repository
Browse files Browse the repository at this point in the history
  • Loading branch information
grixu committed Jul 1, 2024
1 parent 842d440 commit 0049c9c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 64 deletions.
83 changes: 41 additions & 42 deletions build-frontend/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,58 +37,57 @@ inputs:
runs:
using: 'composite'
steps:
- name: Setup node
uses: actions/setup-node@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Registry
uses: docker/login-action@v3
with:
node-version: 18.x
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}

- name: Encode Basic Auth
id: base64-auth
- name: Resolve values of the versions, docker ref & dockerfile path
id: resolve
shell: bash
run: |
echo "BASIC_AUTH_TOKEN=$(echo -n ${{ inputs.cloud_username }}:${{ inputs.cloud_password }} | base64 -w 0)" >> "$GITHUB_OUTPUT"
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
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
env:
FRONTEND: ${{ inputs.frontend }}

- name: Check for existing image
id: check-existing-image
uses: javajawa/check-registry-for-image@v2
with:
registry: ${{ inputs.docker_registry_url }}
auth: "Basic ${{ steps.base64-auth.outputs.BASIC_AUTH_TOKEN }}"
repository: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront
tag: ${{ inputs.version || github.sha }}
tag: ${{ steps.resolve.outputs.version }}

- name: Build and publish docker image (Next.js frontend)
if: ${{ inputs.frontend == 'next' || inputs.frontend == 'nextjs' }}
uses: elgohr/Publish-Docker-Github-Action@v5
- name: Build and publish docker image
uses: docker/build-push-action@v6
if: ${{ steps.check-existing-image.outputs.exists == 'false' }}
with:
name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront:${{ inputs.version || github.sha }}
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}
dockerfile: .vuestorefrontcloud/docker/nextjs/Dockerfile-frontend
buildoptions: --compress
buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,GIT_SHA
env:
NPM_EMAIL: ${{ inputs.npm_email }}
NPM_PASS: ${{ inputs.npm_pass }}
NPM_USER: ${{ inputs.npm_user }}
NPM_REGISTRY: ${{ inputs.npm_registry }}
GIT_SHA: ${{ inputs.version || github.sha }}

- name: Build and publish docker image (Nuxt frontend)
if: ${{ inputs.frontend == 'nuxt' }}
uses: elgohr/Publish-Docker-Github-Action@v5
with:
name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront:${{ inputs.version || github.sha }}
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}
dockerfile: .vuestorefrontcloud/docker/nuxtjs/Dockerfile-frontend
buildoptions: --compress
buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY,GIT_SHA
env:
NPM_EMAIL: ${{ inputs.npm_email }}
NPM_PASS: ${{ inputs.npm_pass }}
NPM_USER: ${{ inputs.npm_user }}
NPM_REGISTRY: ${{ inputs.npm_registry }}
GIT_SHA: ${{ inputs.version || github.sha }}
context: .
file: ${{ steps.resolve.outputs.path }}
push: true
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront:${{ steps.resolve.outputs.version }}
cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront:buildcache"
cache-to: "type=registry,ref=${{ inputs.docker_registry_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 }}
GIT_SHA=${{ steps.resolve.outputs.version }}
49 changes: 27 additions & 22 deletions build-middleware/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,39 +33,44 @@ inputs:
runs:
using: "composite"
steps:
- name: Setup node
uses: actions/setup-node@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Registry
uses: docker/login-action@v3
with:
node-version: 18.x
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}

- name: Encode Basic Auth
id: base64-auth
- name: Resolve values of the versions, docker ref & dockerfile path
id: resolve
shell: bash
run: |
echo "BASIC_AUTH_TOKEN=$(echo -n ${{ inputs.cloud_username }}:${{ inputs.cloud_password }} | base64 -w 0)" >> "$GITHUB_OUTPUT"
echo "version=${{ inputs.version || github.sha }}" >> $GITHUB_OUTPUT
echo "ref=${{ inputs.docker_registry_url }}/${{ inputs.project_name }}-storefrontcloud-io" >> $GITHUB_OUTPUT
- name: Check for existing image
id: check-existing-image
uses: javajawa/check-registry-for-image@v2
with:
registry: ${{ inputs.docker_registry_url }}
auth: "Basic ${{ steps.base64-auth.outputs.BASIC_AUTH_TOKEN }}"
repository: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware
tag: ${{ inputs.version || github.sha }}
tag: ${{ steps.resolve.outputs.version }}

- name: Build and publish docker image (middleware)
uses: elgohr/Publish-Docker-Github-Action@v5
- name: Build and publish docker image
uses: docker/build-push-action@v6
if: ${{ steps.check-existing-image.outputs.exists == 'false' }}
with:
name: ${{ inputs.project_name }}-storefrontcloud-io/vue-storefront-middleware:${{ inputs.version || github.sha }}
registry: ${{ inputs.docker_registry_url }}
username: ${{ inputs.cloud_username }}
password: ${{ inputs.cloud_password }}
dockerfile: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware
buildoptions: --compress
buildargs: NPM_EMAIL,NPM_PASS,NPM_USER,NPM_REGISTRY
env:
NPM_EMAIL: ${{ inputs.npm_email }}
NPM_PASS: ${{ inputs.npm_pass }}
NPM_USER: ${{ inputs.npm_user }}
NPM_REGISTRY: ${{ inputs.npm_registry }}
context: .
file: .vuestorefrontcloud/docker/middleware/Dockerfile-middleware
push: true
tags: ${{ steps.resolve.outputs.ref }}/vue-storefront-middleware:${{ steps.resolve.outputs.version }}
cache-from: "type=registry,ref=${{ inputs.docker_registry_ref }}/vue-storefront-middleware:buildcache"
cache-to: "type=registry,ref=${{ inputs.docker_registry_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 }}

0 comments on commit 0049c9c

Please sign in to comment.