Skip to content

Commit a129c70

Browse files
authored
Merge pull request #1 from tamakiii-sandbox/init
Init
2 parents 663b195 + df78d7f commit a129c70

File tree

8 files changed

+252
-0
lines changed

8 files changed

+252
-0
lines changed

.devcontainer/devcontainer.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.101.0/containers/docker-existing-dockerfile
3+
{
4+
"name": "Existing Dockerfile",
5+
6+
// Sets the run context to one level up instead of the .devcontainer folder.
7+
"context": "..",
8+
9+
// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
10+
"dockerFile": "../Dockerfile",
11+
12+
// Set *default* container specific settings.json values on container create.
13+
"settings": {
14+
"terminal.integrated.shell.linux": null
15+
},
16+
17+
// Add the IDs of extensions you want installed when the container is created.
18+
"extensions": [
19+
"kalitaalexey.vscode-rust",
20+
"rust-lang.rust"
21+
]
22+
23+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
24+
// "forwardPorts": [],
25+
26+
// Uncomment the next line to run commands after the container is created - for example installing git.
27+
// "postCreateCommand": "apt-get update && apt-get install -y git",
28+
29+
// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
30+
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
31+
32+
// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker.
33+
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],
34+
35+
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
36+
// "remoteUser": "vscode"
37+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.env
2+
/target

Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "hello"
3+
version = "0.1.0"
4+
authors = ["tamakiii"]
5+
edition = "2018"
6+
7+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8+
9+
[dependencies]
10+
rand = "0.7.3"

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM rust:1.41.0-alpine3.11 AS production-pseudo
2+
3+
RUN apk add --no-cache make bash && \
4+
sed -i -e 's|/bin/ash|/bin/bash|' /etc/passwd
5+
6+
# --
7+
8+
FROM production-pseudo AS development
9+
10+
ENV PAGER=less
11+
ENV RUSTFLAGS -C target-feature=-crt-static
12+
13+
RUN apk add --no-cache \
14+
git \
15+
bash-doc \
16+
bash-completion \
17+
openssl-dev \
18+
man \
19+
man-pages \
20+
coreutils-doc \
21+
cargo-doc \
22+
rust-doc \
23+
&& \
24+
rustup component add rustfmt
25+
26+
RUN mkdir -p ~/.local/share/bash-completion/completions && \
27+
rustup completions bash >> ~/.local/share/bash-completion/completions/rustup && \
28+
rustup toolchain add nightly && \
29+
rustup component add rust-analysis && \
30+
rustup component add rust-src && \
31+
rustup component add rls
32+
33+
RUN cargo install cargo-edit

Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: install run fmt clean
2+
3+
install:
4+
cargo install --path .
5+
6+
build:
7+
cargo $@
8+
9+
run:
10+
cargo $@
11+
12+
check:
13+
cargo $@
14+
15+
fmt:
16+
cargo $@
17+
18+
clean:
19+
cargo $@
20+

docker.mk

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
.PHONY: init build ash bash run run/% make/% clean
2+
3+
NAME := tamakiii-sandbox/hello-rust
4+
WORK := /app
5+
ENVIRONMENT := $(shell grep '^ENVIRONMENT=' .env | sed -E 's/ENVIRONMENT=//')
6+
CMD := bash
7+
VSC_NAME := vsc-hello-rust-
8+
9+
init: \
10+
.env \
11+
build
12+
13+
.env:
14+
touch $@
15+
echo "ENVIRONMENT=production-pseudo" >> $@
16+
17+
build:
18+
docker build -t $(NAME) --target $(ENVIRONMENT) .
19+
20+
run:
21+
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make run
22+
23+
ash: run/ash
24+
bash: run/bash
25+
26+
run/%:
27+
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) $(@F)
28+
29+
make/%:
30+
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make $(@F)
31+
32+
vsc:
33+
docker exec -it $$(docker container ls | grep $(VSC_NAME) | awk '{ print $$1 }') $(CMD)
34+
35+
clean:
36+
rm .env
37+
docker image rm $(NAME)
38+

src/main.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::io;
2+
use rand::Rng;
3+
4+
fn main() {
5+
println!("Guess the number");
6+
println!("Please input your gess.");
7+
8+
let mut guess = String::new();
9+
10+
io::stdin().read_line(&mut guess)
11+
.expect("failed to read line!!");
12+
13+
let secret_number = rand::thread_rng().gen_range(1, 101);
14+
15+
println!("You guessed: {}", guess);
16+
println!("The secret number is: {}", secret_number);
17+
}

0 commit comments

Comments
 (0)