Skip to content

Commit

Permalink
feat: add cache busting for builds
Browse files Browse the repository at this point in the history
  • Loading branch information
MrOrz committed Oct 21, 2024
1 parent bc0149c commit b573249
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ jobs:
"LOCALE=${{ matrix.locales.locale }}"
# Cache for individual languages
# Ref: https://docs.docker.com/build/cache/backends/gha/#scope
cache-from: type=gha,scope=${{env.GITHUB_REF_NAME}}${{matrix.locales.postfix}}
cache-to: type=gha,mode=max,scope=${{env.GITHUB_REF_NAME}}${{matrix.locales.postfix}}
# Cache busting idea from: https://stackoverflow.com/a/64819132 to handle i18n update issue
cache-from: type=gha,scope=${{env.GITHUB_REF_NAME}}${{matrix.locales.postfix}}${{env.DOCKER_BUILD_CACHE_BUST}}
cache-to: type=gha,mode=max,scope=${{env.GITHUB_REF_NAME}}${{matrix.locales.postfix}}${{env.DOCKER_BUILD_CACHE_BUST}}

- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN npm install
COPY . .

ARG LOCALE=en_US
RUN NODE_ENV=production CACHE_BUST=1 npm run build
RUN NODE_ENV=production npm run build
RUN npm prune --production

#########################################
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ On Heroku, please set `LOCALE` to one of `en_US`, `zh_TW` or any other language

If you want to build using docker instead, you may need to modify Dockerfile to include the desired `LOCALE`.

#### Busting Github Action build cache

Docker build step in Github action are cached, and may contain outdated translation files.

Update the repository variable `DOCKER_BUILD_CACHE_BUST` to skip previous caches.

### Notification setup
- Prerequisites :
1. [LIFF setup](https://github.com/cofacts/rumors-line-bot#liff-setup)
Expand Down

0 comments on commit b573249

Please sign in to comment.