Skip to content
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

CC-1188: add crystal dependency resolution #192

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiled_starters/crystal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
server
4 changes: 2 additions & 2 deletions compiled_starters/crystal/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions compiled_starters/crystal/shard.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2.0
shards:
kiwi:
git: https://github.com/crystal-community/kiwi.git
version: 0.1.0

18 changes: 18 additions & 0 deletions compiled_starters/crystal/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build-your-own-redis
version: 0.1.0

dependencies:
kiwi:
github: crystal-community/kiwi
version: ~> 0.1.0

authors:
- CodeCrafters <hello@codecrafters.io>

targets:
server:
main: app/main.cr

crystal: '>= 1.12.1'

license: MIT
5 changes: 2 additions & 3 deletions compiled_starters/crystal/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#
# DON'T EDIT THIS!
set -e
tmpfile=$(mktemp)
crystal build -o "$tmpfile" app/main.cr
exec "$tmpfile" "$@"
crystal build --progress --stats --time -o server app/main.cr
exec ./server "$@"
14 changes: 14 additions & 0 deletions dockerfiles/crystal-1.12.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 --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
2 changes: 2 additions & 0 deletions solutions/crystal/01-init/code/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
server
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binaries typically get placed in bin/ or so for most languages - what's the default that Crystal uses?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/ is where the dependencies are stored.
And server is the final artifact. (We are passing this name with the -o flag).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other build artifacts would be there in the /app dir.

4 changes: 2 additions & 2 deletions solutions/crystal/01-init/code/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions solutions/crystal/01-init/code/shard.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2.0
shards:
kiwi:
git: https://github.com/crystal-community/kiwi.git
version: 0.1.0

18 changes: 18 additions & 0 deletions solutions/crystal/01-init/code/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build-your-own-redis
version: 0.1.0

dependencies:
kiwi:
github: crystal-community/kiwi
version: ~> 0.1.0

authors:
- CodeCrafters <hello@codecrafters.io>

targets:
server:
main: app/main.cr

crystal: '>= 1.12.1'

license: MIT
5 changes: 2 additions & 3 deletions solutions/crystal/01-init/code/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#
# DON'T EDIT THIS!
set -e
tmpfile=$(mktemp)
crystal build -o "$tmpfile" app/main.cr
exec "$tmpfile" "$@"
crystal build --progress --stats --time -o server app/main.cr
exec ./server "$@"
6 changes: 6 additions & 0 deletions starter-repository-definitions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions starter_templates/codecrafters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions starter_templates/crystal/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib/
server
6 changes: 6 additions & 0 deletions starter_templates/crystal/shard.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2.0
shards:
kiwi:
git: https://github.com/crystal-community/kiwi.git
version: 0.1.0

18 changes: 18 additions & 0 deletions starter_templates/crystal/shard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: build-your-own-redis
version: 0.1.0

dependencies:
kiwi:
github: crystal-community/kiwi
version: ~> 0.1.0

authors:
- CodeCrafters <hello@codecrafters.io>

targets:
server:
main: app/main.cr

crystal: '>= 1.12.1'

license: MIT
5 changes: 2 additions & 3 deletions starter_templates/crystal/spawn_redis_server.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#
# DON'T EDIT THIS!
set -e
tmpfile=$(mktemp)
crystal build -o "$tmpfile" app/main.cr
exec "$tmpfile" "$@"
crystal build --progress --stats --time -o server app/main.cr
exec ./server "$@"
Loading