Skip to content

Commit

Permalink
Docker cache (#3994)
Browse files Browse the repository at this point in the history
* Spytt ut context

* Spytt ut context

* Break all the things

* Docker image as cache

* Slim down image size

* Better named cache
  • Loading branch information
AndreasDybdahl authored Aug 16, 2023
1 parent d622c81 commit 6104d68
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 16 deletions.
40 changes: 27 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,33 +53,47 @@ jobs:
- name: Run tests
run: pnpm exec turbo test

create-build-version:
name: Create build version
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Print context
run: echo "$JSON"
env:
JSON: ${{ toJSON(github) }}
- name: Generate build version
id: generate-build-version
run: echo "build-version=$(date +%Y.%m.%d.%H%M%S)-$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
- name: Generate cache tags
shell: bash
id: generate-cache-tags
env:
GITHUB_REF_NAME: ${{ github.ref_name }}
run: |
GITHUB_REF_NAME=${GITHUB_REF_NAME//\//_}
echo "cache-tag=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
outputs:
build-version: ${{ steps.generate-build-version.outputs.build-version }}
cache-tag: ${{ steps.generate-cache-tags.outputs.cache-tag }}

build-platform-images:
strategy:
matrix:
platform: ['amd64', 'arm64']
name: Build platform images
needs: create-build-version
permissions:
contents: read
packages: write
uses: navikt/fp-gha-workflows/.github/workflows/build-app-frontend-pnpm.yml@main
with:
push-image: ${{ github.ref_name == 'master' }} # default: false
platform: ${{ matrix.platform }}
cache-tag: ${{ needs.create-build-version.outputs.cache-tag }}
secrets: inherit

create-build-version:
name: Create build version
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'master' }}
permissions:
contents: read
steps:
- name: Generate build version
id: generate-build-version
run: echo "build-version=$(date +%Y.%m.%d.%H%M%S)-$(echo $GITHUB_SHA | cut -c1-7)" >> $GITHUB_OUTPUT
outputs:
build-version: ${{ steps.generate-build-version.outputs.build-version }}

create-manifest:
strategy:
matrix:
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ FROM pnpm as prod-deps

COPY --from=prepare /usr/src/app ./

RUN pnpm install --frozen-lockfile --prod
RUN pnpm install --frozen-lockfile --prod \
&& rm -rf "/root/.local/share/pnpm/store"

COPY --from=build /usr/src/app ./

Expand Down
11 changes: 9 additions & 2 deletions docker-bake.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@ variable "GITHUB_REPOSITORY" {
default = "navikt/foreldrepengesoknad"
}

variable "CACHE_TAG" {
default = "latest"
}

group "default" {
targets = ["foreldrepengesoknad", "engangsstonad", "svangerskapspengesoknad", "foreldrepengeoversikt"]
}

target "base" {
dockerfile="Dockerfile"
cache-from=["type=gha"]
cache-to=["type=gha,mode=max"]
cache-from=[
"type=registry,ref=ghcr.io/${GITHUB_REPOSITORY}/build-cache:${CACHE_TAG}",
"type=registry,ref=ghcr.io/${GITHUB_REPOSITORY}/build-cache:master"
]
cache-to=["type=registry,ref=ghcr.io/${GITHUB_REPOSITORY}/build-cache:${CACHE_TAG},mode=max"]
}

target "foreldrepengesoknad" {
Expand Down

0 comments on commit 6104d68

Please sign in to comment.