Skip to content
This repository has been archived by the owner on Oct 12, 2023. It is now read-only.

Sync with languages repo #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
target/
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions Cargo.toml
@@ -0,0 +1,22 @@
# 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]
anyhow = "1.0.43" # for easy error handling
56 changes: 55 additions & 1 deletion README.md
@@ -1 +1,55 @@
# 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 `cargo (1.43)` installed locally
1. Download
[`docker-explorer`](https://github.com/codecrafters-io/docker-explorer), as
[mentioned here](https://github.com/codecrafters-io/docker-explorer).
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
```

(remember to re-run `docker build` each time you make changes to your code!)

# 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 changes: 11 additions & 0 deletions 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 Rust version used to run your code
# on Codecrafters.
#
# Available versions: rust-1.43
language_pack: rust-1.43
24 changes: 24 additions & 0 deletions src/main.rs
@@ -0,0 +1,24 @@
use anyhow::Result;

// Usage: your_docker.sh run <image> <command> <arg1> <arg2> ...
fn main() -> Result<()> {
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()?;
//
// if output.status.success() {
// let std_out = std::str::from_utf8(&output.stdout)?;
// println!("{}", std_out)
// } else {
// std::process::exit(1);
// }

Ok(())

}
12 changes: 12 additions & 0 deletions your_docker.sh
@@ -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" "$@"