Merge pull request #2 from codecrafters-io/sync
Sync with languages repo
This commit is contained in:
commit
22e94e46cc
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
target/
|
1191
Cargo.lock
generated
Normal file
1191
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
Cargo.toml
Normal file
24
Cargo.toml
Normal file
@ -0,0 +1,24 @@
|
||||
# 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!
|
||||
[package]
|
||||
name = "docker-starter-rust"
|
||||
version = "0.1.0"
|
||||
authors = ["Codecrafters <hello@codecrafters.io>"]
|
||||
edition = "2018"
|
||||
|
||||
# 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!
|
||||
[dependencies]
|
||||
reqwest = { version = "0.10", features = ["json", "blocking"] } # http requests
|
||||
bytes = "0.5" # helps wrap responses from reqwest
|
||||
tokio = { version = "0.2", features = ["full"] } # async http requests
|
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@ -0,0 +1,19 @@
|
||||
FROM rust:1.43-buster
|
||||
|
||||
# Download docker-explorer
|
||||
ARG docker_explorer_version=v18
|
||||
RUN curl --fail -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
|
||||
|
||||
# Grab the dependencies and compile them as they dont change much
|
||||
WORKDIR /app
|
||||
COPY Cargo.toml /app/Cargo.toml
|
||||
COPY Cargo.lock /app/Cargo.lock
|
||||
RUN mkdir src && echo "fn main() {}" > "src/main.rs"
|
||||
RUN cargo build --release
|
||||
|
||||
# Grab the real code
|
||||
ADD . /app
|
||||
WORKDIR /app
|
||||
|
||||
ENTRYPOINT ["/app/your_docker.sh"]
|
66
README.md
66
README.md
@ -1 +1,65 @@
|
||||
# docker-starter-rust
|
||||
This is a starting point for Rust 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 signup for early access.
|
||||
|
||||
# Usage
|
||||
|
||||
1. Ensure you have [Docker](https://www.docker.com/) installed locally.
|
||||
1. Follow the details below ("Running your program locally") to run your Docker
|
||||
implementation, which is implemented in `src/main.rs`.
|
||||
1. Commit your changes and run `git push origin master` to submit your solution
|
||||
to CodeCrafters. Test output will be streamed to your terminal.
|
||||
|
||||
# Running your program locally
|
||||
|
||||
Since you'll need to use linux-specific syscalls in this challenge, we'll run
|
||||
your code _inside_ a docker container.
|
||||
|
||||
```sh
|
||||
docker build -t my_docker . && docker run --cap-add="SYS_ADMIN" my_docker run some_image /usr/local/bin/docker-explorer echo hey
|
||||
```
|
||||
|
||||
(The `--cap-add="SYS_ADMIN"` flag is required to create
|
||||
[PID Namespaces](https://man7.org/linux/man-pages/man7/pid_namespaces.7.html))
|
||||
|
||||
To make this easier to type out, you could add a
|
||||
[shell alias](https://shapeshed.com/unix-alias/):
|
||||
|
||||
```sh
|
||||
alias mydocker='docker build -t mydocker . && docker run --cap-add="SYS_ADMIN" mydocker'
|
||||
```
|
||||
|
||||
You can then execute your program like this:
|
||||
|
||||
```sh
|
||||
mydocker run ubuntu:latest /usr/local/bin/docker-explorer echo hey
|
||||
```
|
||||
|
||||
# Passing the first stage
|
||||
|
||||
CodeCrafters runs tests when you do a `git push`. Make an empty commit and push
|
||||
your solution to see the first stage fail.
|
||||
|
||||
```sh
|
||||
git commit --allow-empty -m "Running tests"
|
||||
git push origin master
|
||||
```
|
||||
|
||||
Go to `src/main.rs` and uncomment the implementation. Commit and push your
|
||||
changes to pass the first stage:
|
||||
|
||||
```sh
|
||||
git add .
|
||||
git commit -m "pass the first stage"
|
||||
git push origin master
|
||||
```
|
||||
|
||||
Time to move on to the next stage!
|
||||
|
11
codecrafters.yml
Normal file
11
codecrafters.yml
Normal file
@ -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 Rust version used to run your code
|
||||
# on Codecrafters.
|
||||
#
|
||||
# Available versions: rust-1.43
|
||||
language_pack: rust-1.43
|
20
src/main.rs
Normal file
20
src/main.rs
Normal file
@ -0,0 +1,20 @@
|
||||
// Usage: your_docker.sh run <image> <command> <arg1> <arg2> ...
|
||||
fn main() {
|
||||
println!("Your code goes here!");
|
||||
|
||||
// Uncomment this block to pass the first stage!
|
||||
// let args: Vec<_> = std::env::args().collect();
|
||||
// let command = &args[3];
|
||||
// let command_args = &args[4..];
|
||||
// let output = std::process::Command::new(command)
|
||||
// .args(command_args)
|
||||
// .output()
|
||||
// .unwrap();
|
||||
//
|
||||
// if output.status.success() {
|
||||
// let std_out = std::str::from_utf8(&output.stdout).unwrap();
|
||||
// println!("{}", std_out)
|
||||
// } else {
|
||||
// std::process::exit(1);
|
||||
// }
|
||||
}
|
12
your_docker.sh
Executable file
12
your_docker.sh
Executable file
@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
#
|
||||
# CodeCrafters uses this file to test your code. Don't make any changes here!
|
||||
#
|
||||
# DON'T EDIT THIS!
|
||||
exec cargo run \
|
||||
--quiet \
|
||||
--release \
|
||||
--target-dir=/tmp/codecrafters-docker-target \
|
||||
--manifest-path "$(dirname "$0")/Cargo.toml" "$@"
|
Loading…
x
Reference in New Issue
Block a user