Skip to content

Init #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.101.0/containers/docker-existing-dockerfile
{
"name": "Existing Dockerfile",

// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",

// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../Dockerfile",

// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": null
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"kalitaalexey.vscode-rust",
"rust-lang.rust"
]

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created - for example installing git.
// "postCreateCommand": "apt-get update && apt-get install -y git",

// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
// "remoteUser": "vscode"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.env
/target
95 changes: 95 additions & 0 deletions Cargo.lock

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

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "hello"
version = "0.1.0"
authors = ["tamakiii"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
rand = "0.7.3"
33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM rust:1.41.0-alpine3.11 AS production-pseudo

RUN apk add --no-cache make bash && \
sed -i -e 's|/bin/ash|/bin/bash|' /etc/passwd

# --

FROM production-pseudo AS development

ENV PAGER=less
ENV RUSTFLAGS -C target-feature=-crt-static

RUN apk add --no-cache \
git \
bash-doc \
bash-completion \
openssl-dev \
man \
man-pages \
coreutils-doc \
cargo-doc \
rust-doc \
&& \
rustup component add rustfmt

RUN mkdir -p ~/.local/share/bash-completion/completions && \
rustup completions bash >> ~/.local/share/bash-completion/completions/rustup && \
rustup toolchain add nightly && \
rustup component add rust-analysis && \
rustup component add rust-src && \
rustup component add rls

RUN cargo install cargo-edit
20 changes: 20 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.PHONY: install run fmt clean

install:
cargo install --path .

build:
cargo $@

run:
cargo $@

check:
cargo $@

fmt:
cargo $@

clean:
cargo $@

38 changes: 38 additions & 0 deletions docker.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.PHONY: init build ash bash run run/% make/% clean

NAME := tamakiii-sandbox/hello-rust
WORK := /app
ENVIRONMENT := $(shell grep '^ENVIRONMENT=' .env | sed -E 's/ENVIRONMENT=//')
CMD := bash
VSC_NAME := vsc-hello-rust-

init: \
.env \
build

.env:
touch $@
echo "ENVIRONMENT=production-pseudo" >> $@

build:
docker build -t $(NAME) --target $(ENVIRONMENT) .

run:
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make run

ash: run/ash
bash: run/bash

run/%:
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) $(@F)

make/%:
docker run --rm -it -v $(PWD):$(WORK) -w $(WORK) $(NAME) make $(@F)

vsc:
docker exec -it $$(docker container ls | grep $(VSC_NAME) | awk '{ print $$1 }') $(CMD)

clean:
rm .env
docker image rm $(NAME)

17 changes: 17 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::io;
use rand::Rng;

fn main() {
println!("Guess the number");
println!("Please input your gess.");

let mut guess = String::new();

io::stdin().read_line(&mut guess)
.expect("failed to read line!!");

let secret_number = rand::thread_rng().gen_range(1, 101);

println!("You guessed: {}", guess);
println!("The secret number is: {}", secret_number);
}