Go Development and Execution Environment: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 20: Line 20:
First, identify or build a "builder" image that contains the Go build tools. Let's assume that such an image is <code>example.com/go1.22-builder:latest</code>.
First, identify or build a "builder" image that contains the Go build tools. Let's assume that such an image is <code>example.com/go1.22-builder:latest</code>.


If your project does not declare dependencies on [[Go.mod#Using_Local_Module_Code|local unpublished module code]], it is sufficient to mount the project directory in the build container. However, if the project declares dependencies on local unpublished module code, then we need to mount the directory that contains both source trees. Assuming we're building the project <code>/Users/ovidiu/src/github.com/orgA/projectA</code> and projectA declares a local dependency on <code>../../orgB/projectB</code>, when we need to mount their common parent <code><code>/Users/ovidiu/src/github.com</code>:
If your project does not declare dependencies on [[Go.mod#Using_Local_Module_Code|local unpublished module code]], it is sufficient to mount the project directory in the build container. However, if the project declares dependencies on local unpublished module code, then we need to mount the directory that contains both source trees. Assuming we're building the project <code>/Users/ovidiu/src/github.com/orgA/projectA</code> and projectA declares a local dependency on <code>../../orgB/projectB</code>, when we need to mount their common parent <code>/Users/ovidiu/src/github.com</code>:


<syntaxhighlight lang='bash'>
<syntaxhighlight lang='bash'>

Revision as of 21:40, 5 August 2024

Internal

Overview

The go Tool

go is a tool used to manage source code. More details:

go

Environment Variables

Go Environment Variables

Compilation

go build

Execution

go run

Building a Linux Image on Mac

Once can do cross-compilation or build the executable in a local Linux container. This section describes how to build the executable from a local Linux container.

First, identify or build a "builder" image that contains the Go build tools. Let's assume that such an image is example.com/go1.22-builder:latest.

If your project does not declare dependencies on local unpublished module code, it is sufficient to mount the project directory in the build container. However, if the project declares dependencies on local unpublished module code, then we need to mount the directory that contains both source trees. Assuming we're building the project /Users/ovidiu/src/github.com/orgA/projectA and projectA declares a local dependency on ../../orgB/projectB, when we need to mount their common parent /Users/ovidiu/src/github.com:

docker run --rm -it --mount type=bind,src=/Users/ovidiu/src/github.com,target=/src example.com/go1.22-builder:latest


Run a Linux container based on a Go build image, mount the source directory (or the source directory hierarchy if you are using local unpublished module code) into the container, and build in container.

TODO

Deplete, merge and delete Go Concepts - Runtime