toddsundsted / ktistec

Single user ActivityPub (https://www.w3.org/TR/activitypub/) server.
GNU Affero General Public License v3.0
364 stars 20 forks source link

docker build fails with Error: undefined method 'modification_time' #18

Closed EvanKrall closed 2 years ago

EvanKrall commented 2 years ago

Steps to reproduce:

git clone https://github.com/toddsundsted/ktistec
cd ktistec/
git checkout dist
docker build .

Docker build output:

$ sudo docker build .
Sending build context to Docker daemon  10.23MB
Step 1/18 : FROM crystallang/crystal:latest-alpine AS builder
latest-alpine: Pulling from crystallang/crystal
213ec9aee27d: Pull complete
7ef80f39c1f7: Pull complete
603cc4b4e8d6: Pull complete
04b1137cf375: Pull complete
e2b63715999d: Pull complete
b14b2c4a7d15: Pull complete
Digest: sha256:db7cda4c70606cb02dd8d529a10303b54d2b3315998df915c9068680a1c496ba
Status: Downloaded newer image for crystallang/crystal:latest-alpine
 ---> c5569421363e
Step 2/18 : RUN apk update && apk upgrade && apk add sqlite-static
 ---> Running in 526b6f9cd560
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
v3.16.2-425-gc089bc577f [https://dl-cdn.alpinelinux.org/alpine/v3.16/main]
v3.16.2-422-gd4addd5b8e [https://dl-cdn.alpinelinux.org/alpine/v3.16/community]
OK: 17041 distinct packages available
(1/6) Upgrading alpine-baselayout-data (3.2.0-r22 -> 3.2.0-r23)
(2/6) Upgrading musl (1.2.3-r0 -> 1.2.3-r1)
(3/6) Upgrading alpine-baselayout (3.2.0-r22 -> 3.2.0-r23)
Executing alpine-baselayout-3.2.0-r23.pre-upgrade
Executing alpine-baselayout-3.2.0-r23.post-upgrade
(4/6) Upgrading musl-utils (1.2.3-r0 -> 1.2.3-r1)
(5/6) Upgrading musl-dev (1.2.3-r0 -> 1.2.3-r1)
(6/6) Upgrading tzdata (2022f-r0 -> 2022f-r1)
Executing busybox-1.35.0-r17.trigger
OK: 168 MiB in 52 packages
(1/1) Installing sqlite-static (3.38.5-r0)
OK: 169 MiB in 53 packages
Removing intermediate container 526b6f9cd560
 ---> c3972bcaab5d
Step 3/18 : WORKDIR /build/
 ---> Running in ff8f63ae3c48
Removing intermediate container ff8f63ae3c48
 ---> 89d8cfc65720
Step 4/18 : ARG version
 ---> Running in db70fd06a3c2
Removing intermediate container db70fd06a3c2
 ---> 13aff3a1f670
Step 5/18 : RUN git clone --branch ${version:-dist} --depth 1 https://github.com/toddsundsted/ktistec .
 ---> Running in 871b1df93fbf
Cloning into '.'...
Removing intermediate container 871b1df93fbf
 ---> 2ff4dc1b57d0
Step 6/18 : RUN shards install --production
 ---> Running in 985892dd88ee
Resolving dependencies
Fetching https://github.com/kemalcr/kemal.git
Fetching https://github.com/jeromegn/kilt.git
Fetching https://github.com/toddsundsted/slang.git
Fetching https://github.com/crystal-lang/crystal-sqlite3.git
Fetching https://github.com/toddsundsted/libxml_ext.git
Fetching https://github.com/toddsundsted/openssl_ext.git
Fetching https://github.com/toddsundsted/web_finger.git
Fetching https://github.com/toddsundsted/school.git
Fetching https://github.com/luislavena/radix.git
Fetching https://github.com/crystal-loot/exception_page.git
Fetching https://github.com/sija/backtracer.cr.git
Fetching https://github.com/crystal-lang/crystal-db.git
Fetching https://github.com/toddsundsted/host_meta.git
Installing radix (0.4.1)
Installing backtracer (1.2.1)
Installing exception_page (0.2.2)
Installing kemal (1.1.2)
Installing kilt (0.6.1)
Installing slang (1.7.1 at 64bc795)
Installing db (0.11.0)
Installing sqlite3 (0.19.0)
Installing libxml_ext (0.1.2)
Installing openssl_ext (0.1.4)
Installing host_meta (0.2.3)
Installing web_finger (0.2.4)
Installing school (0.1.0 at bf0034c)
Removing intermediate container 985892dd88ee
 ---> 189eadc8c01d
Step 7/18 : RUN crystal build src/ktistec/server.cr --static --no-debug --release
 ---> Running in fc8aa1c2cdd9
Showing last frame. Use --error-trace for full trace.

In lib/kemal/src/kemal/static_file_handler.cr:55:25

 55 | last_modified = modification_time(file_path)
                      ^----------------
Error: undefined method 'modification_time' for Kemal::StaticFileHandler
The command '/bin/sh -c crystal build src/ktistec/server.cr --static --no-debug --release' returned a non-zero code: 1

Possibly related to https://github.com/kemalcr/kemal/issues/648?

GeopJr commented 2 years ago

This has to do with Crystal >= 1.6.0 and Kemal < 1.3.0. Try using the Dockerfile from the main branch (which uses crystallang/crystal:1.2.2-alpine instead of crystal:latest-alpine).

toddsundsted commented 2 years ago

i will also fix this in the v1.0.0 branch.

toddsundsted commented 2 years ago

i've fixed this in main and in dist. (i'm not going to fix the Dockerfile in the v1.0.0 tag/branch because there are some library issues i've uncovered that i haven't been able to troubleshoot.)

if someone confirms docker build now works i'll close this issue.

@EvanKrall thank you for reporting it!

JayVii commented 2 years ago

successfully built 2.0.0-1, 2.0.0-2 & 2.0.0-3 from the dist branch with the provided Dockerfile (note: 2.0.0-3 required below changes, since there was something wrong with the shards.lock, but that is a different problem entirely)

diff --git a/Dockerfile b/Dockerfile
index 3da5a26..731c3a6 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -3,7 +3,8 @@ RUN apk update && apk upgrade && apk add sqlite-static
 WORKDIR /build/
 ARG version
 RUN git clone --branch ${version:-dist} --depth 1 https://github.com/toddsundsted/ktistec .
-RUN shards install --production
+#RUN shards install --production
+RUN shards update
 RUN crystal build src/ktistec/server.cr --static --no-debug --release

 FROM alpine:latest AS server
EvanKrall commented 2 years ago

I can also confirm that adding RUN shards update to my Dockerfile seems to fix the shards.lock issue, so the build succeeds.

toddsundsted commented 2 years ago

thanks all!