From 46793c8c1a174da6b80aa6758f0fa115f10fbafd Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 10 May 2024 07:13:04 +0000 Subject: [PATCH 1/3] feat: add crystal dependency resolution --- compiled_starters/crystal/.gitignore | 2 ++ compiled_starters/crystal/codecrafters.yml | 4 +-- compiled_starters/crystal/shard.lock | 26 +++++++++++++++++++ compiled_starters/crystal/shard.yml | 20 ++++++++++++++ .../crystal/spawn_redis_server.sh | 5 ++-- dockerfiles/crystal-1.12.Dockerfile | 15 +++++++++++ solutions/crystal/01-init/code/.gitignore | 2 ++ .../crystal/01-init/code/codecrafters.yml | 4 +-- solutions/crystal/01-init/code/shard.lock | 26 +++++++++++++++++++ solutions/crystal/01-init/code/shard.yml | 20 ++++++++++++++ .../01-init/code/spawn_redis_server.sh | 5 ++-- starter-repository-definitions.yml | 6 +++++ starter_templates/codecrafters.yml | 4 +-- starter_templates/crystal/.gitignore | 2 ++ starter_templates/crystal/shard.lock | 26 +++++++++++++++++++ starter_templates/crystal/shard.yml | 20 ++++++++++++++ .../crystal/spawn_redis_server.sh | 5 ++-- 17 files changed, 177 insertions(+), 15 deletions(-) create mode 100644 compiled_starters/crystal/.gitignore create mode 100644 compiled_starters/crystal/shard.lock create mode 100644 compiled_starters/crystal/shard.yml create mode 100644 dockerfiles/crystal-1.12.Dockerfile create mode 100644 solutions/crystal/01-init/code/.gitignore create mode 100644 solutions/crystal/01-init/code/shard.lock create mode 100644 solutions/crystal/01-init/code/shard.yml create mode 100644 starter_templates/crystal/.gitignore create mode 100644 starter_templates/crystal/shard.lock create mode 100644 starter_templates/crystal/shard.yml diff --git a/compiled_starters/crystal/.gitignore b/compiled_starters/crystal/.gitignore new file mode 100644 index 00000000..d1c60ad5 --- /dev/null +++ b/compiled_starters/crystal/.gitignore @@ -0,0 +1,2 @@ +lib/ +server \ No newline at end of file diff --git a/compiled_starters/crystal/codecrafters.yml b/compiled_starters/crystal/codecrafters.yml index ca372bd7..f17cfd9b 100644 --- a/compiled_starters/crystal/codecrafters.yml +++ b/compiled_starters/crystal/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Crystal version used to run your code # on Codecrafters. # -# Available versions: crystal-1.1 -language_pack: crystal-1.1 +# Available versions: crystal-1.12 +language_pack: crystal-1.12 diff --git a/compiled_starters/crystal/shard.lock b/compiled_starters/crystal/shard.lock new file mode 100644 index 00000000..fe6f0606 --- /dev/null +++ b/compiled_starters/crystal/shard.lock @@ -0,0 +1,26 @@ +version: 2.0 +shards: + backtracer: + git: https://github.com/sija/backtracer.cr.git + version: 1.2.2 + + db: + git: https://github.com/crystal-lang/crystal-db.git + version: 0.13.1 + + exception_page: + git: https://github.com/crystal-loot/exception_page.git + version: 0.4.1 + + kemal: + git: https://github.com/kemalcr/kemal.git + version: 1.5.0 + + radix: + git: https://github.com/luislavena/radix.git + version: 0.4.1 + + redis: + git: https://github.com/jgaskins/redis.git + version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + diff --git a/compiled_starters/crystal/shard.yml b/compiled_starters/crystal/shard.yml new file mode 100644 index 00000000..b2153de4 --- /dev/null +++ b/compiled_starters/crystal/shard.yml @@ -0,0 +1,20 @@ +name: helloworld +version: 0.1.0 + +dependencies: + redis: + github: jgaskins/redis + branch: master + kemal: + github: kemalcr/kemal + +authors: + - Ryan + +targets: + helloworld: + main: src/helloworld.cr + +crystal: '>= 1.12.1' + +license: MIT diff --git a/compiled_starters/crystal/spawn_redis_server.sh b/compiled_starters/crystal/spawn_redis_server.sh index f4bd9370..b0e9148c 100755 --- a/compiled_starters/crystal/spawn_redis_server.sh +++ b/compiled_starters/crystal/spawn_redis_server.sh @@ -6,6 +6,5 @@ # # DON'T EDIT THIS! set -e -tmpfile=$(mktemp) -crystal build -o "$tmpfile" app/main.cr -exec "$tmpfile" "$@" +# crystal build -p -s -t -o server app/main.cr +exec ./server "$@" diff --git a/dockerfiles/crystal-1.12.Dockerfile b/dockerfiles/crystal-1.12.Dockerfile new file mode 100644 index 00000000..98e9404a --- /dev/null +++ b/dockerfiles/crystal-1.12.Dockerfile @@ -0,0 +1,15 @@ +FROM crystallang/crystal:1.12-alpine + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="shard.yml, shard.lock" + +WORKDIR /app +COPY shard.yml shard.lock ./ + +RUN shards install --frozen + +RUN mkdir -p /app-cached/ +RUN if [ -d "/app/lib" ]; then mv /app/lib /app-cached/lib; fi + +RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr" > /codecrafters-precompile.sh +# RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr && sed -i '/^crystal/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh +RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/crystal/01-init/code/.gitignore b/solutions/crystal/01-init/code/.gitignore new file mode 100644 index 00000000..d1c60ad5 --- /dev/null +++ b/solutions/crystal/01-init/code/.gitignore @@ -0,0 +1,2 @@ +lib/ +server \ No newline at end of file diff --git a/solutions/crystal/01-init/code/codecrafters.yml b/solutions/crystal/01-init/code/codecrafters.yml index ca372bd7..f17cfd9b 100644 --- a/solutions/crystal/01-init/code/codecrafters.yml +++ b/solutions/crystal/01-init/code/codecrafters.yml @@ -7,5 +7,5 @@ debug: false # Use this to change the Crystal version used to run your code # on Codecrafters. # -# Available versions: crystal-1.1 -language_pack: crystal-1.1 +# Available versions: crystal-1.12 +language_pack: crystal-1.12 diff --git a/solutions/crystal/01-init/code/shard.lock b/solutions/crystal/01-init/code/shard.lock new file mode 100644 index 00000000..fe6f0606 --- /dev/null +++ b/solutions/crystal/01-init/code/shard.lock @@ -0,0 +1,26 @@ +version: 2.0 +shards: + backtracer: + git: https://github.com/sija/backtracer.cr.git + version: 1.2.2 + + db: + git: https://github.com/crystal-lang/crystal-db.git + version: 0.13.1 + + exception_page: + git: https://github.com/crystal-loot/exception_page.git + version: 0.4.1 + + kemal: + git: https://github.com/kemalcr/kemal.git + version: 1.5.0 + + radix: + git: https://github.com/luislavena/radix.git + version: 0.4.1 + + redis: + git: https://github.com/jgaskins/redis.git + version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + diff --git a/solutions/crystal/01-init/code/shard.yml b/solutions/crystal/01-init/code/shard.yml new file mode 100644 index 00000000..b2153de4 --- /dev/null +++ b/solutions/crystal/01-init/code/shard.yml @@ -0,0 +1,20 @@ +name: helloworld +version: 0.1.0 + +dependencies: + redis: + github: jgaskins/redis + branch: master + kemal: + github: kemalcr/kemal + +authors: + - Ryan + +targets: + helloworld: + main: src/helloworld.cr + +crystal: '>= 1.12.1' + +license: MIT diff --git a/solutions/crystal/01-init/code/spawn_redis_server.sh b/solutions/crystal/01-init/code/spawn_redis_server.sh index f4bd9370..b0e9148c 100755 --- a/solutions/crystal/01-init/code/spawn_redis_server.sh +++ b/solutions/crystal/01-init/code/spawn_redis_server.sh @@ -6,6 +6,5 @@ # # DON'T EDIT THIS! set -e -tmpfile=$(mktemp) -crystal build -o "$tmpfile" app/main.cr -exec "$tmpfile" "$@" +# crystal build -p -s -t -o server app/main.cr +exec ./server "$@" diff --git a/starter-repository-definitions.yml b/starter-repository-definitions.yml index 203b80ac..39539225 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -52,6 +52,12 @@ target: codecrafters.yml - source: starter_templates/crystal/app/main.cr target: app/main.cr + - source: starter_templates/crystal/shard.yml + target: shard.yml + - source: starter_templates/crystal/shard.lock + target: shard.lock + - source: starter_templates/crystal/.gitignore + target: .gitignore - source: starter_templates/crystal/spawn_redis_server.sh target: spawn_redis_server.sh - source: starter_templates/.gitattributes diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index 840f183a..6e814402 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -60,8 +60,8 @@ language_pack: java-21 language_pack: nim-1.0 {{/ language_is_nim }} {{# language_is_crystal }} -# Available versions: crystal-1.1 -language_pack: crystal-1.1 +# Available versions: crystal-1.12 +language_pack: crystal-1.12 {{/ language_is_crystal }} {{#language_is_clojure}} # Available versions: clojure-1.10.3 diff --git a/starter_templates/crystal/.gitignore b/starter_templates/crystal/.gitignore new file mode 100644 index 00000000..d1c60ad5 --- /dev/null +++ b/starter_templates/crystal/.gitignore @@ -0,0 +1,2 @@ +lib/ +server \ No newline at end of file diff --git a/starter_templates/crystal/shard.lock b/starter_templates/crystal/shard.lock new file mode 100644 index 00000000..fe6f0606 --- /dev/null +++ b/starter_templates/crystal/shard.lock @@ -0,0 +1,26 @@ +version: 2.0 +shards: + backtracer: + git: https://github.com/sija/backtracer.cr.git + version: 1.2.2 + + db: + git: https://github.com/crystal-lang/crystal-db.git + version: 0.13.1 + + exception_page: + git: https://github.com/crystal-loot/exception_page.git + version: 0.4.1 + + kemal: + git: https://github.com/kemalcr/kemal.git + version: 1.5.0 + + radix: + git: https://github.com/luislavena/radix.git + version: 0.4.1 + + redis: + git: https://github.com/jgaskins/redis.git + version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + diff --git a/starter_templates/crystal/shard.yml b/starter_templates/crystal/shard.yml new file mode 100644 index 00000000..b2153de4 --- /dev/null +++ b/starter_templates/crystal/shard.yml @@ -0,0 +1,20 @@ +name: helloworld +version: 0.1.0 + +dependencies: + redis: + github: jgaskins/redis + branch: master + kemal: + github: kemalcr/kemal + +authors: + - Ryan + +targets: + helloworld: + main: src/helloworld.cr + +crystal: '>= 1.12.1' + +license: MIT diff --git a/starter_templates/crystal/spawn_redis_server.sh b/starter_templates/crystal/spawn_redis_server.sh index f4bd9370..b0e9148c 100755 --- a/starter_templates/crystal/spawn_redis_server.sh +++ b/starter_templates/crystal/spawn_redis_server.sh @@ -6,6 +6,5 @@ # # DON'T EDIT THIS! set -e -tmpfile=$(mktemp) -crystal build -o "$tmpfile" app/main.cr -exec "$tmpfile" "$@" +# crystal build -p -s -t -o server app/main.cr +exec ./server "$@" From 94da2c5edece9ed879718be318f0d4163ed29a86 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 10 May 2024 13:54:01 +0530 Subject: [PATCH 2/3] feat: update metadata for shards file --- compiled_starters/crystal/shard.lock | 26 +++---------------- compiled_starters/crystal/shard.yml | 16 +++++------- .../crystal/spawn_redis_server.sh | 2 +- dockerfiles/crystal-1.12.Dockerfile | 3 +-- solutions/crystal/01-init/code/shard.lock | 26 +++---------------- solutions/crystal/01-init/code/shard.yml | 16 +++++------- .../01-init/code/spawn_redis_server.sh | 2 +- starter_templates/crystal/shard.lock | 26 +++---------------- starter_templates/crystal/shard.yml | 16 +++++------- .../crystal/spawn_redis_server.sh | 2 +- 10 files changed, 34 insertions(+), 101 deletions(-) diff --git a/compiled_starters/crystal/shard.lock b/compiled_starters/crystal/shard.lock index fe6f0606..fe8b8a0d 100644 --- a/compiled_starters/crystal/shard.lock +++ b/compiled_starters/crystal/shard.lock @@ -1,26 +1,6 @@ version: 2.0 shards: - backtracer: - git: https://github.com/sija/backtracer.cr.git - version: 1.2.2 - - db: - git: https://github.com/crystal-lang/crystal-db.git - version: 0.13.1 - - exception_page: - git: https://github.com/crystal-loot/exception_page.git - version: 0.4.1 - - kemal: - git: https://github.com/kemalcr/kemal.git - version: 1.5.0 - - radix: - git: https://github.com/luislavena/radix.git - version: 0.4.1 - - redis: - git: https://github.com/jgaskins/redis.git - version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + kiwi: + git: https://github.com/crystal-community/kiwi.git + version: 0.1.0 diff --git a/compiled_starters/crystal/shard.yml b/compiled_starters/crystal/shard.yml index b2153de4..c9fdaf03 100644 --- a/compiled_starters/crystal/shard.yml +++ b/compiled_starters/crystal/shard.yml @@ -1,19 +1,17 @@ -name: helloworld +name: build-your-own-redis version: 0.1.0 dependencies: - redis: - github: jgaskins/redis - branch: master - kemal: - github: kemalcr/kemal + kiwi: + github: crystal-community/kiwi + version: ~> 0.1.0 authors: - - Ryan + - CodeCrafters targets: - helloworld: - main: src/helloworld.cr + server: + main: app/main.cr crystal: '>= 1.12.1' diff --git a/compiled_starters/crystal/spawn_redis_server.sh b/compiled_starters/crystal/spawn_redis_server.sh index b0e9148c..e76ef76d 100755 --- a/compiled_starters/crystal/spawn_redis_server.sh +++ b/compiled_starters/crystal/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -# crystal build -p -s -t -o server app/main.cr +crystal build -p -s -t -o server app/main.cr exec ./server "$@" diff --git a/dockerfiles/crystal-1.12.Dockerfile b/dockerfiles/crystal-1.12.Dockerfile index 98e9404a..81bbd8dc 100644 --- a/dockerfiles/crystal-1.12.Dockerfile +++ b/dockerfiles/crystal-1.12.Dockerfile @@ -10,6 +10,5 @@ RUN shards install --frozen RUN mkdir -p /app-cached/ RUN if [ -d "/app/lib" ]; then mv /app/lib /app-cached/lib; fi -RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr" > /codecrafters-precompile.sh -# RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr && sed -i '/^crystal/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh +RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr && sed -i '/^crystal/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/crystal/01-init/code/shard.lock b/solutions/crystal/01-init/code/shard.lock index fe6f0606..fe8b8a0d 100644 --- a/solutions/crystal/01-init/code/shard.lock +++ b/solutions/crystal/01-init/code/shard.lock @@ -1,26 +1,6 @@ version: 2.0 shards: - backtracer: - git: https://github.com/sija/backtracer.cr.git - version: 1.2.2 - - db: - git: https://github.com/crystal-lang/crystal-db.git - version: 0.13.1 - - exception_page: - git: https://github.com/crystal-loot/exception_page.git - version: 0.4.1 - - kemal: - git: https://github.com/kemalcr/kemal.git - version: 1.5.0 - - radix: - git: https://github.com/luislavena/radix.git - version: 0.4.1 - - redis: - git: https://github.com/jgaskins/redis.git - version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + kiwi: + git: https://github.com/crystal-community/kiwi.git + version: 0.1.0 diff --git a/solutions/crystal/01-init/code/shard.yml b/solutions/crystal/01-init/code/shard.yml index b2153de4..c9fdaf03 100644 --- a/solutions/crystal/01-init/code/shard.yml +++ b/solutions/crystal/01-init/code/shard.yml @@ -1,19 +1,17 @@ -name: helloworld +name: build-your-own-redis version: 0.1.0 dependencies: - redis: - github: jgaskins/redis - branch: master - kemal: - github: kemalcr/kemal + kiwi: + github: crystal-community/kiwi + version: ~> 0.1.0 authors: - - Ryan + - CodeCrafters targets: - helloworld: - main: src/helloworld.cr + server: + main: app/main.cr crystal: '>= 1.12.1' diff --git a/solutions/crystal/01-init/code/spawn_redis_server.sh b/solutions/crystal/01-init/code/spawn_redis_server.sh index b0e9148c..e76ef76d 100755 --- a/solutions/crystal/01-init/code/spawn_redis_server.sh +++ b/solutions/crystal/01-init/code/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -# crystal build -p -s -t -o server app/main.cr +crystal build -p -s -t -o server app/main.cr exec ./server "$@" diff --git a/starter_templates/crystal/shard.lock b/starter_templates/crystal/shard.lock index fe6f0606..fe8b8a0d 100644 --- a/starter_templates/crystal/shard.lock +++ b/starter_templates/crystal/shard.lock @@ -1,26 +1,6 @@ version: 2.0 shards: - backtracer: - git: https://github.com/sija/backtracer.cr.git - version: 1.2.2 - - db: - git: https://github.com/crystal-lang/crystal-db.git - version: 0.13.1 - - exception_page: - git: https://github.com/crystal-loot/exception_page.git - version: 0.4.1 - - kemal: - git: https://github.com/kemalcr/kemal.git - version: 1.5.0 - - radix: - git: https://github.com/luislavena/radix.git - version: 0.4.1 - - redis: - git: https://github.com/jgaskins/redis.git - version: 0.9.0+git.commit.635d7a34849e661803f7ab84268b2448fcf48a39 + kiwi: + git: https://github.com/crystal-community/kiwi.git + version: 0.1.0 diff --git a/starter_templates/crystal/shard.yml b/starter_templates/crystal/shard.yml index b2153de4..c9fdaf03 100644 --- a/starter_templates/crystal/shard.yml +++ b/starter_templates/crystal/shard.yml @@ -1,19 +1,17 @@ -name: helloworld +name: build-your-own-redis version: 0.1.0 dependencies: - redis: - github: jgaskins/redis - branch: master - kemal: - github: kemalcr/kemal + kiwi: + github: crystal-community/kiwi + version: ~> 0.1.0 authors: - - Ryan + - CodeCrafters targets: - helloworld: - main: src/helloworld.cr + server: + main: app/main.cr crystal: '>= 1.12.1' diff --git a/starter_templates/crystal/spawn_redis_server.sh b/starter_templates/crystal/spawn_redis_server.sh index b0e9148c..e76ef76d 100755 --- a/starter_templates/crystal/spawn_redis_server.sh +++ b/starter_templates/crystal/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -# crystal build -p -s -t -o server app/main.cr +crystal build -p -s -t -o server app/main.cr exec ./server "$@" From b3bc37f9dc6f8abc246d71298ae02dd618b67c49 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Fri, 10 May 2024 22:05:21 +0530 Subject: [PATCH 3/3] feat: update flags passed to crystal build --- compiled_starters/crystal/spawn_redis_server.sh | 2 +- dockerfiles/crystal-1.12.Dockerfile | 4 ++-- solutions/crystal/01-init/code/spawn_redis_server.sh | 2 +- starter_templates/crystal/spawn_redis_server.sh | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiled_starters/crystal/spawn_redis_server.sh b/compiled_starters/crystal/spawn_redis_server.sh index e76ef76d..81691a13 100755 --- a/compiled_starters/crystal/spawn_redis_server.sh +++ b/compiled_starters/crystal/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -crystal build -p -s -t -o server app/main.cr +crystal build --progress --stats --time -o server app/main.cr exec ./server "$@" diff --git a/dockerfiles/crystal-1.12.Dockerfile b/dockerfiles/crystal-1.12.Dockerfile index 81bbd8dc..fb4cd379 100644 --- a/dockerfiles/crystal-1.12.Dockerfile +++ b/dockerfiles/crystal-1.12.Dockerfile @@ -1,6 +1,6 @@ FROM crystallang/crystal:1.12-alpine -ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="shard.yml, shard.lock" +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="shard.yml,shard.lock" WORKDIR /app COPY shard.yml shard.lock ./ @@ -10,5 +10,5 @@ RUN shards install --frozen RUN mkdir -p /app-cached/ RUN if [ -d "/app/lib" ]; then mv /app/lib /app-cached/lib; fi -RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build -p -s -t -o server app/main.cr && sed -i '/^crystal/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh +RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && crystal build --progress --stats --time -o server app/main.cr && sed -i '/^crystal/ s/^/# /' ./spawn_redis_server.sh" > /codecrafters-precompile.sh RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/crystal/01-init/code/spawn_redis_server.sh b/solutions/crystal/01-init/code/spawn_redis_server.sh index e76ef76d..81691a13 100755 --- a/solutions/crystal/01-init/code/spawn_redis_server.sh +++ b/solutions/crystal/01-init/code/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -crystal build -p -s -t -o server app/main.cr +crystal build --progress --stats --time -o server app/main.cr exec ./server "$@" diff --git a/starter_templates/crystal/spawn_redis_server.sh b/starter_templates/crystal/spawn_redis_server.sh index e76ef76d..81691a13 100755 --- a/starter_templates/crystal/spawn_redis_server.sh +++ b/starter_templates/crystal/spawn_redis_server.sh @@ -6,5 +6,5 @@ # # DON'T EDIT THIS! set -e -crystal build -p -s -t -o server app/main.cr +crystal build --progress --stats --time -o server app/main.cr exec ./server "$@"