Set up Go to use your internal registry

Set up Go to use a module proxy by setting environment variables in your workspaces. .Prerequisites

About this task

Procedure

  1. Create a Secret to store the TLS certificate:
    kind: Secret
    apiVersion: v1
    metadata:
      name: tls-cert
      labels:
        controller.devfile.io/mount-to-devworkspace: 'true'
        controller.devfile.io/watch-secret: 'true'
      annotations:
        controller.devfile.io/mount-path: /home/user/certs
        controller.devfile.io/mount-as: file
    type: Opaque
    data:
      tls.cer: >-
        <Base64_encoded_TLS_certificate>

    where:

    <Base64_encoded_TLS_certificate>
    The Base64-encoded content of your Go module proxy’s TLS certificate.
  2. Apply the Secret to your project:
    $ oc apply -f tls-cert.yaml -n <your_namespace>
  3. Create a ConfigMap with Go environment variables:
    Warning:

    Applying a ConfigMap that sets environment variables might cause a workspace boot loop. If you encounter this behavior, remove the ConfigMap and edit the devfile directly.

    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: go-config
      labels:
        controller.devfile.io/mount-to-devworkspace: 'true'
        controller.devfile.io/watch-configmap: 'true'
      annotations:
        controller.devfile.io/mount-as: env
    data:
      GOPROXY: <your_go_proxy_url>
      GONOSUMDB: "*"
      GOPRIVATE: "<your_private_modules>"
      SSL_CERT_FILE: /home/user/certs/tls.cer

    where:

    <your_go_proxy_url>
    The URL of your internal Go module proxy.
    <your_private_modules>
    A comma-separated list of Go module path prefixes for private modules that bypass the proxy and checksum database.
  4. Apply the ConfigMap to your project:
    $ oc apply -f go-config.yaml -n <your_namespace>
  5. Start or restart your workspace.

Results

  1. Open a terminal in your workspace.
  2. Verify the Go configuration:
    $ go env GOPROXY
  3. Download a Go module to verify the configuration:
    $ go get github.com/gin-gonic/gin