A Go Dev Container using mise
to install Go and other convenient tools.
mise
can then be used to install various other Go versions as needed.
- Using the Go Dev Container
- Included Tools
- Using
mise
to Manage Go Versions - Included
.devcontainer
Config - Starship
- Initial Workstation Setup
- Contributions
- Author
The container is stored in the Github Container Registry.
You can use the container in your own dev container config or use the included one.
See the base mise
config file at home/vscode/.config/mise/config.toml
for all tools and versions.
- golang
- golangci-lint
- goreleaser
- bat
- fzf
- gitui
- helm
- k9s
- kubectl
- kubectx
- lsd
- starship
- yq
- Copy the
.mise.toml
file from the root of this repo to your project's root and modify it as needed. - The provided
.devcontainer
will automatically callmise install
to install the custom versions of the applications. - After the container is started and you exec into it,
mise
will automatically install the app versions listed in the.mise.toml
file. - Other applications can also be installed by editing the
.mise.toml
file.
Runmise help
for examples.
This repository also includes an example on how to use the built Go dev container.
Do the following to use this example.
- Clone down the repository.
git clone https://github.com/sarg3nt/go-dev-container.git
- 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. - Copy the
.devcontainer
directory to your project. - Copy the following files to the root of your project.
These are optional but encouraged..mise.toml
: The config file for managing specific versions of tooling you need for your Go project.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 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
Once you've followed the above instructions to copy the needed files to your project, perform the following to configure them.
Edit the devcontainer.json
file to make the following changes.
- Change
name
fromgo-dev-container
to the name of your project. - Change
--name
inrunargs
fromgo-dev-container
to the name of your project. - Change
source=go-dev-container-bashhistory
tosource=<YOUR-PROJECT>-bashhistory
- Change
source=go-dev-container-plugins
tosource=<YOUR-PROJECT>-plugins
NOTE: You may be tempted to find and replace
go-dev-container
with the name of your project, however theimage
for the container is calledgo-dev-container
so that would break things. If you want to do a controlled replacement you can, just be careful not to replace that one line.
This script is used to easily start VSCode and exec into the Dev Container from the terminal that it is ran from. This frees the developer from having to use the VSCode integrated terminal.
You can run dev.sh
in multiple terminals once VSCode is running and the container has started to easily exec into it.
- Open the
dev.sh
file and set adocker_exec_command
if desired, this is optional but if this repo is used a lot, it is a nice to have. This will create a command in the users.bashrc
and.zshrc
to quickly exec into this running dev container. - Change
project_name
to match the name of the repository.
Example: If your root project repository is calledmy-go-project
then setproject_name
tomy-go-project
To use the ./dev.sh
script, simply run it, then when VS Code opens, there should be a prompt at the bottom right of the editor saying "Folder contains a Dev Container . . .". Click the "Reopen in Container" button and VS Code will open the dev container and attach to it.
NOTE: If you have not opened the dev container before or if it has been updated it will download the container from Github, which can take a while.
Starship is a custom Power Line command prompt we include.
For Starship to function properly you need a Nerd Font installed from Nerd Fonts Downloads.
See Initial Workstation Setup for instructions on downloading and installing the fonts.
Instructions to set up your workstation. For more information on Dev Containers check out the official docs.
- If you will be building Docker containers in Windows, then install Docker Desktop for Windows following Docker's instructions. If you do not need Docker for Windows support then you can directly install Docker inside of Ubuntu AFTER you install WSL and Ubuntu in the following steps.
- Install VS Code from the Visual Studio Code website or from the Microsoft Store.
- Open VS Code and click on the "Extensions" button to the left.
- Search for "Dev Containers" and install it.
- Search for "WSL" and install it.
- WSL is the Windows Subsystem for Linux and facilitates the use of a Linux distruction on Windows.
Follow the Microsoft insructions to install WSL and a Linux distribution. Ubuntu is probably the most commong Linux OS used in WSL, but feel free to choose what you want. Note that the dev container itself uses Rocky Linux but this shouldn't matter to you during use.
To get the full functionality of font ligatures and icons for the Starship prompt you will need to install a Nerd Font from Nerd Fonts Downloads. If you skip this step the Dev Container terminal command line will look weird and not have icons thus making it harder to read.
Many of us use FiraCode Nerd Font or FiraMono Nerd Font but you can preview any of the fonts and choose which one is best for you.
Download your chosen font and install it in Windows then proceed to the next step.
- Open Windows Terminal, select the menu chevron to the right of the last tab and select settings.
- On the left select
Profiles
-->Defaults
- Under
Additional Settings
selectAppearance
- Under
Font Face
select the name of the font you downloaded, for example if you chose the "Firacode Nerd Font" then you'd chooseFiracode NF
You may need to checkShow all items
or restart Windows Terminal to see the new fonts.
See How to Install New (or Nerd) Fonts on Linux (Ultimate Guide) for instructions.
The fonts must be installed in your operating system to be used in VSCode. If you are running VSCode on Windows and using it in Linux inside of WSL you would still install the fonts in Windows.
-
Select
File
-->Preferences
-->Settings
-
Expand
Text Editor
--> selectFont
-
In the
Font Family
text box paste the following:NOTE: This assumes you chose "FiraCode NF", if not, replace the first font name with the name of the font you installed in Windows.
'FiraCode NF', 'CaskaydiaCove NF', Consolas, 'Courier New', monospace
Contributions are welcome via the standard Github Fork --> PR process.
David Sargent
- dave [at] sarg3.net
- GitHub at sarg3nt