From 0b2d6a9c23e403532a9af3eb15ae70c77429fd24 Mon Sep 17 00:00:00 2001 From: Jedd Dryden <40693089+Jaffa-Cakes@users.noreply.github.com> Date: Wed, 14 Feb 2024 10:06:42 +1100 Subject: [PATCH] Dev Container Implementation and README.md Updates (#47) * Implemented Dev Container * Added extra extensions * Improved `README.md` * Typo * Update .devcontainer/Dockerfile Co-authored-by: Toby Scott * Update README.md Co-authored-by: Toby Scott * Update README.md Co-authored-by: Toby Scott * Update README.md Co-authored-by: Toby Scott * Update README.md Co-authored-by: Toby Scott * Update README.md Co-authored-by: Toby Scott * Update Dockerfile --------- Co-authored-by: Toby Scott --- .devcontainer/Dockerfile | 12 ++++++++++ .devcontainer/book.sh | 5 ++++ .devcontainer/devcontainer.json | 40 ++++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 24 +++++++++++++++++++ README.md | 38 +++++++++++++++++++++++------- 5 files changed, 111 insertions(+), 8 deletions(-) create mode 100644 .devcontainer/Dockerfile create mode 100755 .devcontainer/book.sh create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..06c3020 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,12 @@ +FROM rust:1 + +# Install MDBook and other CLI tools +RUN rustup component add rustfmt clippy && \ + cargo install mdbook --version 0.4.* && \ + cargo install mdbook-admonish --version 1.* + +# Tell git to trust "dubious" ownership +RUN git config --global --add safe.directory /repository + +# Entry directory for non-vscode containers based on this image +WORKDIR /repository diff --git a/.devcontainer/book.sh b/.devcontainer/book.sh new file mode 100755 index 0000000..871fcdf --- /dev/null +++ b/.devcontainer/book.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# This script is executed from the root of the repository in the book container. + +# Serve the MDBook +mdbook serve -n '0.0.0.0' -p '3000' \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..e7507c1 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,40 @@ +{ + "name": "Leptos Book", + "dockerComposeFile": ["docker-compose.yml"], + "service": "devcontainer", + "workspaceFolder": "/repository", + "shutdownAction": "stopCompose", + "initializeCommand": "echo 'Starting devcontainer...'", + "forwardPorts": ["book:3000"], + "customizations": { + "vscode": { + "extensions": [ + // Docker + "ms-azuretools.vscode-docker", + // Copilot + "github.copilot", + "github.copilot-chat", + // Github + "github.vscode-pull-request-github", + // Prettier + "esbenp.prettier-vscode", + // Rust + "rust-lang.rust-analyzer", + "vadimcn.vscode-lldb", + // TOML Highlighting + "tamasfe.even-better-toml", + // Markdown Tools + "yzhang.markdown-all-in-one" + ], + "settings": { + "editor.defaultFormatter": "esbenp.prettier-vscode", + "editor.formatOnSave": true, + "editor.formatOnPaste": true, + "editor.tabSize": 4 + } + } + }, + "mounts": [ + "source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind" + ] +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..cc94a36 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3.8" + +name: leptos-book + +services: + devcontainer: + build: + context: ./.. + dockerfile: .devcontainer/Dockerfile + volumes: + - ./..:/repository + # VSCode needs a second to be able to attach to the container + command: /bin/sh -c "while sleep 1000; do :; done" + + book: + build: + context: ./../ + dockerfile: .devcontainer/Dockerfile + volumes: + - ./..:/repository + expose: + - 3000 + # Run the book + command: .devcontainer/book.sh diff --git a/README.md b/README.md index 7424338..062b392 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,45 @@ -This project contains the core of a new introductory guide to Leptos. +# Leptos Book -It is built using `mdbook`. You can view a local copy by installing `mdbook` +- [Leptos Book](#leptos-book) + - [Introduction](#introduction) + - [Building the Book](#building-the-book) + - [Optional: VSCode Dev Container](#vscode-dev-container) + +## Introduction + +This project contains the core of a new introductory guide to Leptos. Pull requests for any typos, clarification, or improvements are always welcome. + +You can find the live version of this book on the [Leptos Website](https://book.leptos.dev/). + +## Building the Book + +It is built using [`mdbook`](https://crates.io/crates/mdbook). You can view a local copy by installing `mdbook` with Cargo. ```sh -cargo install mdbook +cargo install mdbook --version 0.4.* ``` -This book also uses an mdbook preprocessor called `mdbook-admonish` to style blocks of text like notes, warnings, etc. - -Install mdbook admonish using: +This book also uses an mdbook preprocessor called [`mdbook-admonish`](https://crates.io/crates/mdbook-admonish) to style blocks of text like notes, warnings, etc. ```sh -cargo install mdbook-admonish +cargo install mdbook-admonish --version 1.* ``` + and then run the book with + ```sh mdbook serve ``` -It should be available at `http://localhost:3000`. +It should now be available at [`http://localhost:3000`](http://localhost:3000). +## Optional: VSCode Dev Container + +You can optionally build and run it in the example [VSCode Dev Container](https://code.visualstudio.com/docs/devcontainers/containers), which will automatically install all dependencies, build the book, and serve it at [`http://localhost:3000`](http://localhost:3000) with live reloading. + +Install Docker and the official [Dev Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension, then open the project in VSCode and "Reopen in dev container" when prompted. + +For more info, see: https://code.visualstudio.com/remote/advancedcontainers/use-docker-kubernetes + +To run Docker commands inside the dev container, see: https://code.visualstudio.com/remote/advancedcontainers/use-docker-kubernetes