-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dockerfile with pnpm and Elixir 1.16 #87
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 5 5
Lines 199 199
=========================================
Hits 199 199 ☔ View full report in Codecov by Sentry. |
ARG OTP_VERSION=26.0.2 | ||
ARG DEBIAN_VERSION=bullseye-20231009-slim | ||
ARG ELIXIR_VERSION=1.16.2 | ||
ARG OTP_VERSION=25.3.2.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why the OTP_VERSION
downgrade? Elixir 1.16.x
is compatible with OTP 26
... 💭
https://hexdocs.pm/elixir/main/compatibility-and-deprecations.html#between-elixir-and-erlang-otp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same question ! But no image with OPT26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble understanding why we're introducing pnpm
in this project. I haven't used it in this project so far. Though I agree pnpm
is certainly a better alternative to npm
, I don't see why we have to use it in the Dockerfile
(and subsequently downgrade the OTP version).
Can you clarify this for me, please? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LuchoTurtle
I believe we used pnpm
because of #36 to install "properly" the dependency "[email protected]" (and I used it as well for "[email protected]"). As you said, pnpm
is a much better alternative to simply npm
. Bringing it in the Docker image is easy (once you know how to)!.
Then we don't downgrade subsequently the OTP because of this. It is downgraded because of the upgrade to v1.16. You chosed the image from hex.pm and it does not seem to offer 1.16+26 at the moment. However, the "official" https://hub.docker.com/_/elixir/ seems to offer 1.16+26.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you prefer, it looks like 1.16.1+26 is available, but 1.16.2 comes with 25. Probably a question of time.
ARG ELIXIR_VERSION=1.16.1
ARG OTP_VERSION=26.2.3
ARG DEBIAN_VERSION=bullseye-20240130
https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=1.16.1
https://github.com/fly-apps/hello_elixir/blob/main/Dockerfile
Then the node
version in the Dockerfile runs on Linux, is v12.2 I believe, and you need to bring in npm
which is probably good enough to install your package. On the other side, I presume you are running node
on OSX in dev mode, which is just different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👌
How to test a Docker image?I fought a little bit, and my process ends with an error 137 (out of memory) ?? (I have only 8G RAM, Docker+MacOS) Hopefully it works, so if you have a better way, I take it. We can whether use
docker run -d -p 5001:5000 --name registry registry:2.7
docker build --build-args="MIX_ENV=prod" -t localhost:5001/img:latest . where the Dockerfile uses a build-arg to switch Mix modes:
docker push localhost:5001/img-[dev/prod]:latest
The 1st option uses
Check he Fly.io blog on running migrations The 2d option works only for a newly created database. Clean the generated file below and save it. mix ecto.create && mix ecto.migrate --log-migrations-sql > ./init.sql
# init-db.sh
#!/bin/bash
set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" -d "$POSTGRES_DB" -v db="$POSTGRES_DB" -v user="$POSTGRES_USER" -e <<-EOSQL
GRANT ALL PRIVILEGES ON DATABASE :db TO :user;
CREATE TABLE "images" (
"id" bigserial,
"url" varchar(255),
"description" varchar(255),
"width" integer,
"height" integer,
"inserted_at" timestamp(0) NOT NULL,
"updated_at" timestamp(0) NOT NULL,
PRIMARY KEY ("id")
);
ALTER TABLE "images"
ADD COLUMN "idx" bigint,
ADD COLUMN "sha1" varchar(255);
CREATE UNIQUE INDEX "images_sha1_index" ON "images" ("sha1");
CREATE UNIQUE INDEX "images_idx_index" ON "images" ("idx");
CREATE TABLE IF NOT EXISTS "hnswlib_index" (
"id" bigserial,
"lock_version" integer DEFAULT 1,
"file" bytea,
PRIMARY KEY ("id")
);
EOSQL
# .env-prod-docker
MIX_ENV=prod
POSTGRES_PASSWORD=postgres
POSTGRES_USER=postgres
POSTGRES_DB=app_prod
PGDATA=var/lib/postgresql/data/pg-data
SECRET_KEY_BASE=qhSXOpnkmvYzf3/maxi4/pg+WkVnYkhp
DATABASE_URL=ecto://postgres:postgres@db:5432/app_prod
PHX_SERVER=true
docker compose up # docker-compose.yml
version: "3.9"
volumes:
pg-data:
driver: local
services:
db:
image: postgres:15.3-bullseye
env_file:
- .env-docker
restart: always
volumes:
- pg-data:/var/lib/postgresql/data/pg-data
- ./init.sql:/docker-entrypoint-initdb.d/init.sh:ro
ports:
- 5432:5432
app:
build:
context: .
args:
- MIX_ENV
# OR
image: localhost:5001/img-[dev/prod]:latest
depends_on:
- db
env_file:
- .env-docker
ports:
- 4000:4000 |
Thanks @ndrean ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Match code with Dockerfile.
The Dockerfile builds correctly. I did not use it nor tested the deployment of course.
Why?
You seemed to have had problems with
npm
in the dev mode and used successfullypnpm
to overcome this.For the Dockerfile, you don't use
pnpm
and I assume it works.If you want to match the code with the Dockerfile, you may want to use
pnpm
too.How?
For this, you need to install a recent
Node.js
version viacURL
(Debian comes with v12 installed whilstpnpm
requires >v16).Note that
node
comes withnpm
.You can use the Dockerfile below.