Skip to content

Commit

Permalink
updates to docker build etc
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdc committed Jan 19, 2025
1 parent 7c8513c commit 3720891
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
19 changes: 13 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# COPY package.json yarn.lock ./
# RUN yarn set version berry && yarn install

FROM node:20-alpine as build
FROM --platform=linux/amd64 node:20-alpine as build
WORKDIR /usr/src/app
COPY . .
# COPY --from=deps /usr/src/app/node_modules ./node_modules
Expand All @@ -21,10 +21,17 @@ ENV NEXT_TELEMETRY_DISABLED 1
# RUN
# mv ./node_modules ./node_modules.tmp \
# && mv ./node_modules.tmp ./node_modules \
RUN yarn generate \
&& yarn add --dev typescript @types/node \
&& yarn build \
&& npm prune --production

# RUN yarn generate \
# && yarn add --dev typescript @types/node \
# && yarn build \
# && npm prune --omit=dev

RUN yarn generate
RUN yarn add --dev typescript @types/node
RUN yarn build
# RUN npm prune --omit=dev
#--production

# this gets huge and we do not need it for the final build
RUN rm -rf .next/cache
Expand All @@ -34,7 +41,7 @@ RUN rm -rf .next/cache
# RUN rm node_modules/@prisma/engines/prisma-fmt-linux-musl

## Shrink final image, copy built nextjs and startup the server
FROM node:20-alpine
FROM --platform=linux/amd64 node:20-alpine

WORKDIR /usr/src/app
ENV NODE_ENV production
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ endif

.PHONY: build
build:
docker-compose build
# DOCKER_DEFAULT_PLATFORM=linux/amd64 docker-compose build
docker buildx --platform linux/amd64 bake -f docker-compose.yml

.PHONY: run-local
run-local:
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ You can also create a tar of the docker image by running:
make save-image
```

If you are an a newer Mac using an Apple Silicon chip (M1, M2, ...) then you will need to make sure that you can build and target `linux/amd64`. The easiest way
is to use [Docker Desktop](https://www.docker.com/products/docker-desktop/) and then to install the emulators.
```
docker run --privileged --rm tonistiigi/binfmt --install all
```
The builds are slower this way then [some of the other options](https://docs.docker.com/build/building/multi-platform/) but it works with little ceremony.

The other commands are meant to be used on the server (at least until we get some deployment automation in place).

## Technical Overview
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ version: '3.7'

services:
gallformers:
platform: linux/amd64
build:
context: .
dockerfile: ./Dockerfile
Expand All @@ -11,5 +12,7 @@ services:
environment:
PORT: 3000
command: yarn start

x-bake:
platforms:
- linux/amd64

Binary file modified prisma/gallformers.sqlite
Binary file not shown.

0 comments on commit 3720891

Please sign in to comment.