Go Development and Execution Environment

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

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