Skip to content

Commit

Permalink
Refactor build-and-push Docker image workflow
Browse files Browse the repository at this point in the history
This commit refactors the build-and-push Docker image workflow in order to improve code readability and maintainability. Specifically, it modifies the YAML file to set up environment variables, define job steps, configure caching for Docker layers, and enable BuildKit with QEMU.

The changes include:
- Renaming the workflow file to "docker-build.yml"
- Setting the workflow name as "Build and Push Docker Image"
- Modifying the "runs-on" and "strategy" sections to use dynamic values
- Adding caching for Docker layers to improve build performance
- Enabling BuildKit with QEMU for compatibility across platforms
- Adjusting the "with" section of various steps to reference environment variables
- Updating the Docker build and push action with platform specifications

Additionally, the Dockerfile is modified to install npm with a `maxsockets` parameter of 1, which limits the number of concurrent network requests during package installation.
  • Loading branch information
realashleybailey committed Oct 4, 2023
1 parent 2a12c7f commit b92ee84
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 74 deletions.
60 changes: 0 additions & 60 deletions .github/workflows/docker-build-test.yml

This file was deleted.

35 changes: 22 additions & 13 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and push Docker image
name: Build and Push Docker Image

on:
push:
Expand All @@ -11,15 +11,27 @@ env:

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
platform: [linux/amd64, linux/arm64]

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /var/lib/docker
key: docker-${{ runner.os }}-${{ github.sha }}

- name: Set up QEMU and enable BuildKit
uses: docker/setup-qemu-action@v1
with:
platforms: all

- name: Log into registry
uses: docker/login-action@v1
with:
Expand All @@ -32,20 +44,17 @@ jobs:
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: ${{ github.ref_name }} # use branch name as tag

- name: Set up QEMU
uses: docker/setup-qemu-action@v1
tags: ${{ github.ref_name }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
platforms: linux/amd64,linux/arm64 # specify architectures here
context: .
file: ./Dockerfile
push: true # set this to false if you don't want to push
tags: ${{ steps.meta.outputs.tags }} # use metadata action output
labels: ${{ steps.meta.outputs.labels }} # use metadata action output
push: true
platforms: ${{ matrix.platform }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ RUN npm install -g npm@latest

# Build Frontend Environment
WORKDIR /data/frontend
RUN npm install
RUN npm install --maxsockets 1
RUN npm run build

# Setup Timezone
Expand Down

0 comments on commit b92ee84

Please sign in to comment.