Template for working with Go in Docker via VSCode remote containers.
Extracted from allaboutapps/go-starter.
ToC:
Requires the following local setup for development:
- Docker CE (19.03 or above)
- Docker Compose (1.25 or above)
- VSCode Extension: Remote - Containers (
ms-vscode-remote.remote-containers
)
This project makes use of the Remote - Containers extension provided by Visual Studio Code. A local installation of the Go tool-chain is no longer required when using this setup.
Please refer to the official installation guide how this works for your host OS and head to our FAQ: How does our VSCode setup work? if you encounter issues.
Create a new git repository through the GitHub template repository feature (use this template). You will then start with a single initial commit in your own repository.
# Clone your new repository, cd into it, then easily start the docker-compose dev environment through our helper
./docker-helper.sh --up
You should be inside the 'service' docker container with a bash shell.
development@94242c61cf2b:/app$ # inside your container...
# Shortcut for make init, make build, make info and make test
make all
# Print all available make targets
make help
If you are new to VSCode Remote - Containers feature, see our FAQ: How does our VSCode setup work?.
Run CMD+SHIFT+P
Go: Install/Update Tools
after attaching to the container with VSCode to auto-install all golang related vscode extensions.
Other useful commands while developing your service:
development@94242c61cf2b:/app$ # inside your container...
# Print all available make targets
make help
# Shortcut for make init, make build, make info and make test
make all
# Init install/cache dependencies and install tools to bin
make init
# Rebuild only after changes to files
make
# Execute all tests
make test
Full docker build:
docker build . -t go-docker-vscode
docker run go-docker-vscode
# Hello World
Simply run ./docker-helper --destroy
in your working directory (on your host machine) to wipe all docker related traces of this project (and its volumes!).
MIT © Mario Ranftl