Skip to content

Commit

Permalink
Add an install.sh file to make installing the .devcontainer and other…
Browse files Browse the repository at this point in the history
… files easier for end users.
  • Loading branch information
sarg3nt committed Oct 29, 2024
1 parent 7e76c4c commit 1183021
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ See the base `mise` config file at `home/vscode/.config/mise/config.toml` for al

1. Copy the `.mise.toml` file from the root of this repo to your project's root and modify it as needed.
1. The provided `.devcontainer` will automatically call `mise install` to install the custom versions of the applications.
1. After the container is started and you shell into it `mise` will automatically install the versions listed in the `.mise.toml` file.
1. After the container is started and you exec into it, `mise` will automatically install the app versions listed in the `.mise.toml` file.
1. Other applications can also be installed by editing the `.mise.toml` file.
Run `mise help` for examples.

## Included `.devcontainer` Config

This repository not only builds a Go dev container into a Docker container it also includes example usage in the `.devcontainer` directory.
This repository also includes an example on how to use the built Go dev container.

Do the following to use this example.

1. Clone down the repository.
1. Clone down the repository.
`git clone https://github.com/sarg3nt/go-dev-container.git`
2. Ensure your target project does not already have a `.devcontainer` directory. If it does, you will either need to rename it for testing or delete it.
3. Copy the `.devcontainer` directory to your project.
4. Copy the following files to the root of your project.
Expand All @@ -71,6 +74,11 @@ Do the following to use this example.
- `cspell.json`: The cspell config for spell checking in your project, edit to add any specific words that your project needs.
- `dev.sh`: Helps launch VSCode and exec into the dev container. This file needs some modification to use in your repository. See [dev.sh](#devsh) for instructions.

We've included an `install.sh` script to automate the process of copying the above files into your project directory.
The script must be ran from the root of the `go-dev-container` project.
Example:
`./install.sh ~/src/my-go-project`

### Dev Container Setup

Once you've followed the above instructions to copy the needed files to your project, perform the following to configure them.
Expand Down
66 changes: 66 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
#
# This script will start the dev container and open an interactive prompt into it.
#

set -euo pipefail
IFS=$'\n\t'

# Check if user is using Docker Deskop for Windows or the native Docker Engine.
main() {
# shellcheck source=/dev/null
if [[ ! -f "usr/bin/lib/sh/colors.sh" ]]; then
echo "You do not appear to be in the go-dev-container project directory."
echo "This script must be ran from the root of the go-dev-container project directory."
exit 1
fi
source "usr/bin/lib/sh/colors.sh"

local project_path=""
project_path="${1-}"
if [[ -z "${project_path}" ]]; then
echo -e "${RED}The path to your project was not passed in and is required.${NC}"
echo -e "${CYAN}Usage:${NC} $0 <path-to-your-project>"
exit 1
fi

# Remove trailing slash from project_path if it exists
project_path="${project_path%/}"

if [[ ! -d "${project_path}" ]]; then
echo -e "${RED}The path to your project does not exist.${NC}"
exit 1
fi

echo -e "${BLUE}This script will copy the following directories and files into${NC} ${project_path}"
echo -e " .devcontainer"
echo -e " .mise.toml"
echo -e " cspell.json"
echo -e " dev.sh"
read -r -p "$(echo -e "${CYAN}Do you wish to continue? (y/n): ${NC}")" response
if [[ "$response" != "y" ]]; then
echo -e "${RED}Aborting.${NC}"
exit 1
fi
echo ""

echo -e "${BLUE}Copying files to ${project_path}${NC}"

echo -e " ${GREEN}Copying${NC} .devcontainer ${GREEN}directory${NC}"
cp -r ".devcontainer" "${project_path}/"
echo -e " ${GREEN}Copying${NC} .mise.toml"
cp ".mise.toml" "${project_path}/"
echo -e " ${GREEN}Copying${NC} cspell.json"
cp "cspell.json" "${project_path}/"
echo -e " ${GREEN}Copying${NC} dev.sh"
cp "dev.sh" "${project_path}/"

echo ""
echo -e "${CYAN}You must now update the values in the${NC} ${project_path}/.devcontainer/devcontainer.json ${CYAN}and${NC} ${project_path}/dev.sh ${CYAN}files.${NC}"
echo -e "${CYAN}See${NC} README.md ${CYAN}for instructions.${NC}"

}

if ! (return 0 2>/dev/null); then
(main "$@")
fi

0 comments on commit 1183021

Please sign in to comment.