Skip to content

Commit 5b37ce4

Browse files
author
Gary Miller
committed
enabed caching for local docker buildx bake
1 parent a48c8c8 commit 5b37ce4

4 files changed

Lines changed: 25 additions & 6 deletions

File tree

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Dockerfile
33
**/node_modules/**
44
docker-compose.yml
55
docker-compose.dev.yml
6+
docker/.buildx-cache
67
doc/**
78
.dockerignore
89
**/build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,6 @@ yarn-error.log
2525

2626
# api-extractor temp files
2727
temp/
28+
29+
# Docker buildx local layer cache
30+
docker/.buildx-cache

doc/docker.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ The `-v $(pwd):/local` mount makes your current directory available at `/local`
110110

111111
The `ohm-dev:latest` images is 1.62 GB and is 97% efficient with only 64 MB potentially wasted space.
112112

113-
### Publishing to Docker Hub
113+
### Publishing to Docker Hub (from development machine)
114+
115+
**Note: it is perferable to have the gha docker-release.yml do this**
116+
But there can be a chicken and egg situation where it is easier to do this from a development machine.
114117

115118
Build and push a versioned image to Docker Hub using the git tag as the version:
116119

117120
```sh
118121
# if not set default to ohmjs (ie docker hub using the ohmjs org)
119122
export DOCKER_REPO=<custom docker repo>
120-
# if not set defaults to 'development'
121-
export VERSION=$(cat packages/compiler/package.json | jq -r '.version')
122-
# or export VERSION=$(git describe --tag --dirty)
123123

124124
# # it might be necessary (particularly on osx) to create a new builder
125125
# # the default builder might not support multi-platform builds
@@ -133,10 +133,19 @@ export VERSION=$(cat packages/compiler/package.json | jq -r '.version')
133133
# assuming DHPAT contains your PAT
134134
echo $DHPAT | docker login -u <personal username> --password-stdin
135135
cd docker
136-
docker buildx bake --allow=fs.read=.. --push
136+
# if not set defaults to 'development'
137+
export VERSION=$(cat ../packages/compiler/package.json | jq -r '.version')
138+
docker buildx use ohmjs-builder
139+
docker buildx bake \
140+
--set="*.cache-from=type=local,src=.buildx-cache" \
141+
--set="*.cache-to=type=local,dest=.buildx-cache,mode=max" \
142+
--allow=fs.read=.. \
143+
--push
137144
```
138145

139-
`git describe --tag --dirty` produces a version string based on the nearest git tag, appending commit info and a `-dirty` suffix if there are uncommitted changes.
146+
Builds use a local layer cache stored in `docker/.buildx-cache`.
147+
On subsequent runs this avoids re-downloading base layers and reinstalling dependencies.
148+
Note the `docker/.buildx-cache` directory is over 1GB, and needs to be cleaned up manually.
140149

141150
The defaults in `docker-compose.yml` are `DOCKER_REPO=ohmjs` and `VERSION=development`. See [docker-compose.yml](../docker/docker-compose.yml) for details.
142151

docker/docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ services:
1919
platforms:
2020
- linux/amd64
2121
- linux/arm64/v8
22+
# # Not specifying cache here as it would just slow down gha builds.
23+
# # When doing local development, see docker.md for instructions on how to use it local cache.
24+
# cache-from:
25+
# - type=local,src=.buildx-cache
26+
# cache-to:
27+
# - type=local,dest=.buildx-cache,mode=max
2228
target: ${TARGET:-dist}
2329
volumes:
2430
- .:/local

0 commit comments

Comments
 (0)