Skip to content

Commit

Permalink
Merge pull request #209 from UW-Macrostrat/dockerfile-speed
Browse files Browse the repository at this point in the history
Improve layer caching in Dockerfile
  • Loading branch information
davenquinn authored May 25, 2024
2 parents e2d46be + ca50775 commit 3f4a8f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
name: Build Development
name: Build image

on:
push:
branches: ["main"]
tags:
- v[0-9]+.[0-9]+.[0-9]+ # Semver Release (non-prerelease)
pull_request:
branches: [main]

Expand All @@ -19,15 +21,20 @@ jobs:
uses: docker/metadata-action@v4
with:
images: hub.opensciencegrid.org/macrostrat/web
# New: apply the 'latest' tag to non-prerelease semver tags
tags: |
type=semver,pattern={{version}}
type=raw,value=sha-{{sha}}
type=raw,value=latest-itb
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, '-')}}
type=raw,value=latest-itb-{{date 'YYYYMMDDHHmmss'}}
type=ref,event=pr,suffix=-{{date 'YYYYMMDDHHmmss'}}
type=ref,event=branch,suffix=-{{date 'YYYYMMDDHHmmss'}}
type=ref,event=tag,suffix=-{{date 'YYYYMMDDHHmmss'}}
type=raw,value=latest-itb-{{date 'YYYYMMDDHHmmss'}}
type=raw,value=sha-{{sha}}
- name: Set up Docker Buildx
type=semver,pattern={{version}}
type=semver,pattern={{version}}-{{date 'YYYYMMDDHHmmss'}}
flavor: |
latest=false
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2
- name: Login to OSG DockerHub
uses: docker/login-action@v2
Expand Down
43 changes: 0 additions & 43 deletions .github/workflows/build-prod.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/test-build.yaml

This file was deleted.

28 changes: 26 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,38 @@ RUN apt-get update && apt-get install -y rsync
ENV NODE_ENV=production

WORKDIR /usr/src/app
COPY . ./
COPY .yarn/releases .yarn/releases
COPY .yarnrc.yml yarn.lock package.json ./

# Copy only the elements needed for a Yarn install to take advantage of
# Docker's layer caching
# This is complex because we are working with multiple workspaces.

# Copy package JSON files with wildcards
# This scoops up all package.json files in the directory and subdirectories
# to deal with Yarn workspaces. However it requires BUILDKIT to be enabled,
# which is done by setting DOCKER_BUILDKIT=1 in the environment
RUN --mount=type=bind,target=/docker-context \
cd /docker-context/; \
find . -name "package.json" -mindepth 0 -maxdepth 5 -exec cp --parents "{}" /usr/src/app/ \;

RUN yarn install --immutable

# Load the cache from the previous build
RUN --mount=type=cache,target=/yarn-cache \
rsync -a /yarn-cache/ .yarn/cache \
rsync -a /yarn-cache/ .yarn/cache/ \
&& yarn install --immutable \
&& rsync -a .yarn/cache/ /yarn-cache

# # Remove rsync
RUN apt-get remove -y rsync

# # Now we can run the full copy command

COPY . ./

ENV NODE_ENV=production

RUN yarn run build

EXPOSE 3000
Expand Down

0 comments on commit 3f4a8f5

Please sign in to comment.