aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcodecrafters-bot <hello@codecrafters.io>2024-06-02 20:04:15 +0000
committercodecrafters-bot <hello@codecrafters.io>2024-06-02 20:04:15 +0000
commitbab5e32bd62071304ec1cd865859e685bf6d9b23 (patch)
treecb07d921130962c3887f3570ed70e45553879f83
downloaddocker-go-bab5e32bd62071304ec1cd865859e685bf6d9b23.tar.gz
docker-go-bab5e32bd62071304ec1cd865859e685bf6d9b23.zip
init [skip ci]
-rw-r--r--.gitattributes1
-rw-r--r--Dockerfile15
-rw-r--r--README.md51
-rw-r--r--app/main.go28
-rw-r--r--codecrafters.yml11
-rw-r--r--go.mod11
-rw-r--r--go.sum0
-rwxr-xr-xyour_docker.sh11
8 files changed, 128 insertions, 0 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..176a458
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+* text=auto
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..576f3b4
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1,15 @@
+FROM golang:1.22-alpine
+
+RUN apk add --no-cache 'curl>=7.66'
+
+# Download docker-explorer
+ARG docker_explorer_version=v18
+RUN curl -Lo /usr/local/bin/docker-explorer https://github.com/codecrafters-io/docker-explorer/releases/download/${docker_explorer_version}/${docker_explorer_version}_linux_amd64
+RUN chmod +x /usr/local/bin/docker-explorer
+
+COPY . /app
+WORKDIR /app
+
+RUN sed -i -e 's/\r$//' /app/your_docker.sh
+
+ENTRYPOINT ["/app/your_docker.sh"]
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7e543ba
--- /dev/null
+++ b/README.md
@@ -0,0 +1,51 @@
+[![progress-banner](https://backend.codecrafters.io/progress/docker/f7cecf9e-c40b-4dc9-b7d5-206bb7c9e509)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
+
+This is a starting point for Go solutions to the
+["Build Your Own Docker" Challenge](https://codecrafters.io/challenges/docker).
+
+In this challenge, you'll build a program that can pull an image from
+[Docker Hub](https://hub.docker.com/) and execute commands in it. Along the way,
+we'll learn about [chroot](https://en.wikipedia.org/wiki/Chroot),
+[kernel namespaces](https://en.wikipedia.org/wiki/Linux_namespaces), the
+[docker registry API](https://docs.docker.com/registry/spec/api/) and much more.
+
+**Note**: If you're viewing this repo on GitHub, head over to
+[codecrafters.io](https://codecrafters.io) to try the challenge.
+
+# Passing the first stage
+
+The entry point for your Docker implementation is `app/main.go`. Study and
+uncomment the relevant code, and push your changes to pass the first stage:
+
+```sh
+git add .
+git commit -m "pass 1st stage" # any msg
+git push origin master
+```
+
+That's all!
+
+# Stage 2 & beyond
+
+Note: This section is for stages 2 and beyond.
+
+You'll use linux-specific syscalls in this challenge. so we'll run your code
+_inside_ a Docker container.
+
+Please ensure you have [Docker installed](https://docs.docker.com/get-docker/)
+locally.
+
+Next, add a [shell alias](https://shapeshed.com/unix-alias/):
+
+```sh
+alias mydocker='docker build -t mydocker . && docker run --cap-add="SYS_ADMIN" mydocker'
+```
+
+(The `--cap-add="SYS_ADMIN"` flag is required to create
+[PID Namespaces](https://man7.org/linux/man-pages/man7/pid_namespaces.7.html))
+
+You can now execute your program like this:
+
+```sh
+mydocker run alpine:latest /usr/local/bin/docker-explorer echo hey
+```
diff --git a/app/main.go b/app/main.go
new file mode 100644
index 0000000..d1c4195
--- /dev/null
+++ b/app/main.go
@@ -0,0 +1,28 @@
+package main
+
+import (
+ "fmt"
+ // Uncomment this block to pass the first stage!
+ // "os"
+ // "os/exec"
+)
+
+// Usage: your_docker.sh run <image> <command> <arg1> <arg2> ...
+func main() {
+ // You can use print statements as follows for debugging, they'll be visible when running tests.
+ fmt.Println("Logs from your program will appear here!")
+
+ // Uncomment this block to pass the first stage!
+ //
+ // command := os.Args[3]
+ // args := os.Args[4:len(os.Args)]
+ //
+ // cmd := exec.Command(command, args...)
+ // output, err := cmd.Output()
+ // if err != nil {
+ // fmt.Printf("Err: %v", err)
+ // os.Exit(1)
+ // }
+ //
+ // fmt.Println(string(output))
+}
diff --git a/codecrafters.yml b/codecrafters.yml
new file mode 100644
index 0000000..77886cf
--- /dev/null
+++ b/codecrafters.yml
@@ -0,0 +1,11 @@
+# Set this to true if you want debug logs.
+#
+# These can be VERY verbose, so we suggest turning them off
+# unless you really need them.
+debug: false
+
+# Use this to change the Go version used to run your code
+# on Codecrafters.
+#
+# Available versions: go-1.22
+language_pack: go-1.22
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..2f97604
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,11 @@
+// DON'T EDIT THIS!
+//
+// Codecrafters relies on this file being intact to run tests successfully. Any changes
+// here will not reflect when CodeCrafters tests your code, and might even cause build
+// failures.
+//
+// DON'T EDIT THIS!
+
+module github.com/codecrafters-io/docker-starter-go
+
+go 1.22
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/go.sum
diff --git a/your_docker.sh b/your_docker.sh
new file mode 100755
index 0000000..439ca82
--- /dev/null
+++ b/your_docker.sh
@@ -0,0 +1,11 @@
+#!/bin/sh
+#
+# DON'T EDIT THIS!
+#
+# CodeCrafters uses this file to test your code. Don't make any changes here!
+#
+# DON'T EDIT THIS!
+set -e
+tmpFile=$(mktemp)
+go build -o "$tmpFile" app/*.go
+exec "$tmpFile" "$@"