Skip to content

Commit 88935a7

Browse files
committed
Add Scala 3.7 Dockerfile and project structure for HTTP server challenge
- Introduced Dockerfile for Scala 3.7 with SBT setup. - Created project files including build.sbt, .gitignore, and scripts for local and remote execution. - Implemented basic server code in App.scala with connection handling. - Added configuration for CodeCrafters integration.
1 parent b9d537d commit 88935a7

File tree

21 files changed

+321
-0
lines changed

21 files changed

+321
-0
lines changed

dockerfiles/scala-3.7.Dockerfile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# syntax=docker/dockerfile:1.7-labs
2+
FROM maven:3.9.9-eclipse-temurin-24-noble
3+
4+
ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.sbt,project/assembly.sbt,project/build.properties"
5+
6+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
7+
8+
RUN echo "deb https://repo.scala-sbt.org/scalasbt/debian all main" | tee /etc/apt/sources.list.d/sbt.list
9+
10+
RUN echo "deb https://repo.scala-sbt.org/scalasbt/debian /" | tee /etc/apt/sources.list.d/sbt_old.list
11+
12+
RUN curl -sL "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0x2EE0EA64E40A89B84B2DF73499E82A75642AC823" | gpg --no-default-keyring --keyring gnupg-ring:/etc/apt/trusted.gpg.d/scalasbt-release.gpg --import && \
13+
chmod 644 /etc/apt/trusted.gpg.d/scalasbt-release.gpg
14+
15+
RUN apt-get update && \
16+
apt-get install --no-install-recommends sbt=1.11.7 -yqq && \
17+
apt-get clean && \
18+
rm -rf /var/lib/apt/lists/*
19+
20+
ENV PATH=/usr/local/sbt/bin:$PATH
21+
22+
# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
23+
COPY --exclude=.git --exclude=README.md . /app
24+
25+
WORKDIR /app
26+
27+
RUN .codecrafters/compile.sh
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to compile your program on CodeCrafters
4+
#
5+
# This runs before .codecrafters/run.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
# The option is needed for Java 17+ to allow native memory access operations.
12+
SBT_OPTS="--enable-native-access=ALL-UNNAMED" sbt assembly
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
#
3+
# This script is used to run your program on CodeCrafters
4+
#
5+
# This runs after .codecrafters/compile.sh
6+
#
7+
# Learn more: https://codecrafters.io/program-interface
8+
9+
set -e # Exit on failure
10+
11+
exec java -jar ./target/scala-3.7.4/http-server.jar "$@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# macOS
2+
.DS_Store
3+
4+
# sbt specific
5+
dist/*
6+
debug/
7+
target/
8+
lib_managed/
9+
src_managed/
10+
project/boot/
11+
project/plugins/project/
12+
project/local-plugins.sbt
13+
.history
14+
.ensime
15+
.ensime_cache/
16+
.sbt-scripted/
17+
local.sbt
18+
19+
# Bloop
20+
.bsp
21+
22+
# VS Code
23+
.vscode/
24+
25+
# Metals
26+
.bloop/
27+
.metals/
28+
metals.sbt
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/http-server.png)
2+
3+
This is a starting point for Scala solutions to the
4+
["Build Your Own HTTP server" Challenge](https://app.codecrafters.io/courses/http-server/overview).
5+
6+
[HTTP](https://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol) is the
7+
protocol that powers the web. In this challenge, you'll build a HTTP/1.1 server
8+
that is capable of serving multiple clients.
9+
10+
Along the way you'll learn about TCP servers,
11+
[HTTP request syntax](https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html),
12+
and more.
13+
14+
**Note**: If you're viewing this repo on GitHub, head over to
15+
[codecrafters.io](https://codecrafters.io) to try the challenge.
16+
17+
# Passing the first stage
18+
19+
The entry point for your HTTP server implementation is in
20+
`src/main/scala/codecrafters_http_server/App.scala`. Study and uncomment the
21+
relevant code, and push your changes to pass the first stage:
22+
23+
```sh
24+
git commit -am "pass 1st stage" # any msg
25+
git push origin master
26+
```
27+
28+
Time to move on to the next stage!
29+
30+
# Stage 2 & beyond
31+
32+
Note: This section is for stages 2 and beyond.
33+
34+
1. Ensure you have `sbt (1.11.7)` installed locally
35+
1. Run `./your_program.sh` to run your program, which is implemented in
36+
`src/main/scala/codecrafters_http_server/App.scala`.
37+
1. Commit your changes and run `git push origin master` to submit your solution
38+
to CodeCrafters. Test output will be streamed to your terminal.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
ThisBuild / scalaVersion := "3.7.4"
2+
ThisBuild / version := "0.1.0-SNAPSHOT"
3+
ThisBuild / organization := "com.codecrafters"
4+
ThisBuild / organizationName := "CodeCrafters"
5+
6+
assembly / assemblyJarName := "http-server.jar"
7+
8+
lazy val root = (project in file("."))
9+
.settings(
10+
name := "codecrafter-http-server",
11+
// List your dependencies here
12+
libraryDependencies ++= Seq(
13+
)
14+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set this to true if you want debug logs.
2+
#
3+
# These can be VERY verbose, so we suggest turning them off
4+
# unless you really need them.
5+
debug: false
6+
7+
# Use this to change the Scala version used to run your code
8+
# on Codecrafters.
9+
#
10+
# Available versions: scala-3.7
11+
buildpack: scala-3.7
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=1.11.7

0 commit comments

Comments
 (0)