1
0
Go to file
2024-06-11 16:28:36 +00:00
_constraints [info=c1a0bf9372442b858f737250ee76e662] 2023-06-13 20:30:49 +00:00
_service [info=7a1d371041e453a2f3dded4aa7ed639a] 2024-02-07 19:23:02 +00:00
.gitattributes [info=c1a0bf9372442b858f737250ee76e662] 2023-06-13 20:30:49 +00:00
.gitignore [info=c1a0bf9372442b858f737250ee76e662] 2023-06-13 20:30:49 +00:00
Dockerfile [info=e359941b4937f83d27c94f49b0d1a45a] 2024-06-05 16:00:11 +00:00
golang-stable-image.changes [info=8769c79e834691043a8d587c3e6bbc39] 2024-06-10 15:14:21 +00:00
README.md [info=8769c79e834691043a8d587c3e6bbc39] 2024-06-10 15:14:21 +00:00

Go 1.22 development Container Image

Redistributable

Description

Go (a.k.a., Golang) is a statically-typed programming language, with syntax loosely derived from C. Go offers additional features such as garbage collection, type safety, certain dynamic-typing capabilities, additional built-in types (for example, variable-length arrays and key-value maps) as well as a large standard library.

Usage

To compile and deploy an application, copy the sources, fetch dependencies (assuming go.mod is used for dependency management), and build the binary:

# Build the application using the Go 1.22 development Container Image
FROM registry.opensuse.org/opensuse/bci/golang:1.22 as build

WORKDIR /app

# pre-copy/cache go.mod for pre-downloading dependencies and only redownloading them in subsequent builds if they change
COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . ./

# Make sure to build the application with CGO disabled.
# This will force Go to use some Go implementations of code
# rather than those normally supplied by the host operating system.
# You need this for scratch images as those supporting libraries
# are not available.
RUN CGO_ENABLED=0 go build -o /hello

# Bundle the application into a scratch image
FROM scratch

COPY --from=build /hello /hello

CMD ["/hello"]

Build and run the container image:

$ podman build -t my-golang-app .
$ podman run -it --rm my-golang-app

There are situations when you don't want to run an application inside a container.

To compile the application, without running it inside a container instance, use the following command:

$ podman run --rm -v "$PWD":/app:Z -w /app registry.opensuse.org/opensuse/bci/golang:1.22 go build -v

To run the application tests inside a container, use the following command:

$ podman run --rm -v "$PWD":/app:Z -w /app registry.opensuse.org/opensuse/bci/golang:1.22 go test -v

Note: The Golang image should be used as a build environment. For runtime, self-contained Go binaries should use a scratch image and for applications that require external dependencies use the bci-base image.

Additional tools

The following additional tools are included in the image:

  • go1.22-race
  • make
  • git-core

Licensing

SPDX-License-Identifier: MIT

This documentation and the build recipe are licensed as MIT. The container itself contains various software components under various open source licenses listed in the associated Software Bill of Materials (SBOM).

This image is based on openSUSE Tumbleweed.