Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
Continuous Development with Docker and VSCode
— Go VersionSource Image: https://www.getwrecked.com/self-compiling-go-docker-container/TL;DR. The proposed solutions are about:
- Establish Docker container and integrate with project file on the host directory
- Use debug module in VSCode for Go
- Separation of Docker images based on purpose — base, debug, production
weisurya/go-docker-continuous-development
As a Windows user who needs to work with other developers that are using other operating systems, such as Ubuntu or MacOS, I usually become discouraged whether my work could be run on the others or not. Even when I am using the same operating system with the others, having an issue regarding the different environment is still common. So, Docker is a solution, for a developer like me, who does not want to spend a lot of times to debug this repetitive issue.
Establish Docker container and integrate with project file on the host directory
There is a drawback when I am using Docker for development — I am still writing and running the code in my host. I do not think that Docker could solve my concern regarding the different environment. When I am still in the development stage, I do not want to build so often — I want to have a way where I could only use Docker container as the environment, but still could code-on-demand. For this one, you could check here.
The diagram above provides a high-overview of how this methodology works. By mount-binding between the directory of your current project directory and the directory inside your container. So, whenever you make any changes in your local machine, it would directly reflect inside your Docker container. Hence, it solves the problem of:
- Different environment between machines.
- Continuous development without putting the code and build it together as a Docker image.
Use debug module in VSCode for Go
Also, as a Microsoft Visual Code user, I love to use their debug module. It really helps me to develop a huge scale project, trace the flow step-by-step. However, by default, It only supports for the Node.js runtime and can debug JavaScript, TypeScript, and any other Javascript-backed language. Fortunately, VSCode has an open-source market where we could find Debuggers extensions on there. I write step-by-step tutorial on here.
The diagram above provides a high-overview of how this methodology works. The idea is simple, we want to make a backdoor for go-delve to listen to the system inside the container. On here, I expose the container to another port, which is 1234 on the example.
Separation of Docker images based on purpose — base, debug, production
Also, since I want to debug in Docker, I do not want to mix it with the stack that I only want to have in my production container. So I split the Dockerfile based on its purpose. I write the idea and the usage of each file on here.
The diagram above provides a high-overview of how this methodology works. by doing this approach, we could make sure that:
- Your Docker image would keep small.
- You only put relevant packages in each environment.
- You still maintain the standard between production and test image.
I hope this tutorial could help you to enjoy your development time in Go language much better! I am happy to hear your feedback.
Nevertheless, happy coding!
Surya is a Software Engineer in his professional life and a Technology Evangelist in his personal life. This year, he builds a resolution, called “Learn to Unlearn and Keep Sharing”. If you are interested or want to follow his progress, you can visit him at his personal website, soensurya.com, or on LinkedIn.
References
- golang
- Debugging in Visual Studio Code
- Use bind mounts
- Go with Visual Studio Code
- Seccomp security profiles for Docker
- go-delve/delve
Continuous Development with Docker and VSCode — Go Version was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.