Pushing a Go module to a registry
Before pushing, prepare a ZIP archive of your Go module. For more information, see Creating a Go module.
-
Create the following environment variables depending on the authentication method:
IAM tokenAPI key-
Get an IAM token for the Yandex account or service account you are going to use for authentication.
-
Create the
REGISTRY_USERNAMEandREGISTRY_PASSWORDenvironment variables:export REGISTRY_USERNAME="iam" export REGISTRY_PASSWORD="<IAM_token>"Where:
REGISTRY_USERNAME: Authentication method.REGISTRY_PASSWORD: Body of the previously obtained IAM token.
Note
The IAM token's lifetime is limited to 12 hours.
-
Create an API key for the service account you are going to use for authentication.
When creating a key, specify its scope:
yc.cloud-registry.artifacts.pull: To pull artifacts from the registry.yc.cloud-registry.artifacts.push: To push artifacts to the registry.
-
Create the
REGISTRY_USERNAMEandREGISTRY_PASSWORDenvironment variables:export REGISTRY_USERNAME="api_key" export REGISTRY_PASSWORD="<API_key>"Where:
REGISTRY_USERNAME: Authentication method.REGISTRY_PASSWORD: Body of the previously created API key.
Note
The API key maximum lifetime is set manually when you create the key.
-
-
Push the Go module using a PUT HTTP request:
curl \ --request PUT \ --user "$REGISTRY_USERNAME:$REGISTRY_PASSWORD" \ --header "X-Checksum-SHA256: <file_hash>" \ --upload-file <local_path_to_ZIP_file> \ https://registry.yandexcloud.net/go/<registry_ID>/<module_name>/<module_version>/<file_name_in_registry>Where:
-
--request: Method. -
--user: Authentication data. -
--header: API request header. This is an optional parameter.In the
X-Checksum-SHA256header, you can specify the hash of the file you are pushing to check the file’s integrity after it is pushed. You can generate the hash, e.g., using this command:openssl dgst -sha256 <file_path> | awk '{print $2}' -
--upload-file: Local path to the ZIP file. -
The request URL contains the registry URL, the Go module name and version, and the file name in the registry. For example:
https://registry.yandexcloud.net/go/cn15fqbr806r********/mymodule/1.0.0/mymodule-v1.0.0.zip
Warning
In the URL, provide the Go module version without the
vprefix; e.g., for versionv1.0.0, specify1.0.0.Warning
When publishing a Go module, do not prefix its name with
registry.yandexcloud.net/go/<registry_ID>/. If your Go module's major version is greater than 1, omit the/vNsuffix as well. This means, for aregistry.yandexcloud.net/go/<registry_ID>/sample/module/v4Go module, usesample/moduleas its name. -
Scope is an API key parameter that restricts the key's use to specific operations in addition to the service account's access permissions. For details, see API keys with scope and validity limits.