A base workflow for Golang projects, layout inspired by the Golang standards.
Docker + Golang + inspiration from standards.
Goflow must be installed from a clean repository (existing and nothing to validate).
Create a new one if needed:
git init
echo 'TODO' > ./README.md
git add .
git commit -m "Initial commit"Get goflow directory, in an existing Git repository:
# get the goflow subtree
git remote add goflow git@github.com:Nicolab/goflow.git
git fetch goflow
git subtree add --prefix=goflow --squash goflow master
# create the Docker volume folder
mkdir ./goflow/build/dev/.goEdit the config file: ./goflow/conf/dev/docker.sh (mainly: dev_container_name).
From now on you need the files of your project (go.mod, main.go).
If your project directory is empty, you can use the minimal Go Flow Project Layout as inspiration (or starter kit).
Then, always from your project directory:
./goflow/build/dev/build-image # create goflow-dev image
./goflow/scripts/dev/console # run the container and get a shell insideNow, from the container:
./goflow/scripts/dev/install-container-stack
./goflow/scripts/dev/watch # or ./goflow/scripts/dev/watch-debugIt's installed!
Happy Coding in the Go flow ;)
See the config files.
Run/exec the goflow-dev container:
./goflow/scripts/dev/consoleStop and remove goflow-dev container:
./goflow/scripts/dev/rm-containerExecute the Go program (go run by default):
./goflow/scripts/dev/execRun the Go program and watch the code change (for reloading):
./goflow/scripts/dev/watchSame with Delve:
./goflow/scripts/dev/watch-debugNow, you can connect your favorite code editor to the Delve server.
From the host you can also exec:
dlv connect localhost:2345
or in one:dlv connect localhost:2345 & ./goflow/scripts/dev/console
If you need to keep your Go Flow up to date with the recent changes made to Go Flow project, you can always fetch and merge them from this repo back into your own project:
git pull -s subtree goflow master --allow-unrelated-histories
--allow-unrelated-historiesprevent that Git refusing to merge unrelated histories.
If you want to add or to update a remote branch to track:
git remote add -t master goflow git@github:Nicolab/goflow.git
git remote add -t remote-branch remote-name remote-url
You can use multiple "-t branch" options to grab multiple branches.
Remove the goflow directory:
rm -rf goflowRemove the remote URL:
git remote rm goflowVerify it's gone:
git remote -v
Note:git remote rmdoes not delete the remote repository from the server. It simply removes the remote and its references from your local repository.
To customize the .bashrc file, you can mount the .bashrc file in volume via ./goflow/conf/dev/docker.sh file.
Example:
-v "${PWD}"/goflow/build/dev/files/.bashrc:/home/gopher/.bashrc \You can mount as many files and folders as you want. It's a simple Docker command that you can customize at will!
If you reach the default limit of your OS, you should increase the amount of inotify watchers.
If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal that set a new limit temporary:
sudo sysctl fs.inotify.max_user_watches=524288 \
&& sudo sysctl -p \
&& cat /proc/sys/fs/inotify/max_user_watches- Handle locales in build/dev/Dockerfile.
- Improve the concept (symplify the install, usage and add more docs).
MIT (c) 2018, Nicolas Tallefourtane.
| Nicolas Talle |