Skip to content

Commit

Permalink
Merge pull request #49 from shgtkshruch/dockerfile-prod-ci
Browse files Browse the repository at this point in the history
Pass `RAILS_MASTER_KEY` through docker secret
  • Loading branch information
shgtkshruch committed Jul 31, 2021
2 parents 1093b12 + a818c68 commit 68e3228
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ jobs:
file: ./Dockerfile.prod
push: true
tags: ${{ steps.login-ecr.outputs.registry }}/chronos/rails:${{ github.sha }}
secrets: |
"master_key=${{ secrets.RAILS_MASTER_KEY }}"
cache-from: |
type=local,src=/tmp/.buildx-cache-new/bundle
type=local,src=/tmp/.buildx-cache-new/npm
Expand Down
6 changes: 3 additions & 3 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ COPY . .
COPY --from=bundle /app/vendor/bundle /app/vendor/bundle
COPY --from=npm /app/node_modules node_modules

# Set a dummy value to avoid errors when building docker image.
# refs: https://github.com/rails/rails/issues/32947
RUN SECRET_KEY_BASE=dummy bin/rails assets:precompile \
# refs: https://github.com/rails/rails/issues/32947#issuecomment-653478965
RUN --mount=type=secret,id=master_key,dst=/app/config/master.key \
bin/rails assets:precompile \
&& rm -rf tmp/cache/*

FROM base AS main
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
$ COMPOSE_DOCKER_CLI_BUILD=1 docker-compose build
```

Build docker image for production.

```sh
$ docker build -f Dockerfile.prod --secret id=master_key,src=config/master.key .
```

## Dev

```sh
Expand Down

0 comments on commit 68e3228

Please sign in to comment.