Тип сервиса
Сервис Go
Среда выполнения Go для сборки API, воркеров и собственных приложений из исходного кода с необязательными связями с базой данных, кешем и почтой.
Этот сервис запускает ваш код: его образ собирается из Git-репозитория, а каждая сборка развёртывается в окружение.
В StackMaster
Как Go работает в StackMaster
Build and start
The service's Dockerfile copies the repository to /usr/src/app and, when there are .go files at its root:
- runs
go mod downloadwhengo.modexists; - runs
go build -o /home/wodby/go/bin/app .
The container starts that binary as app. So with the service's Dockerfile the main package must be at the root of the repository. A pipeline that passes a Dockerfile from the repository (wodby ci build go -f Dockerfile) uses that file instead; it must still end with a command that starts the server.
- The application must listen on port 8080, on all interfaces. That is the port of the service's HTTP endpoint. The service sets no
PORTvariable in a deployed environment: default to 8080 in the code. - The service sets no other variable for the application and generates no configuration file.
- The service declares no volume of its own: files written inside the container are lost when it is replaced.
Linked services
Links to other services reach the application as environment variables. Nothing in the image reads them: the application reads them itself. Do not hardcode hosts or credentials.
| Link | Variables |
|---|---|
| Database (MariaDB, MySQL or PostgreSQL) | DB_HOST, DB_PORT, DB_NAME (also DB_DATABASE), DB_USERNAME, DB_PASSWORD, DB_DRIVER (also DB_CONNECTION) |
SMTP_HOST, SMTP_PORT | |
| Redis or Valkey | REDIS_HOST, REDIS_PORT, REDIS_PASSWORD |
| OpenTelemetry Collector | OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_EXPORTER_OTLP_PROTOCOL (http/protobuf), OTEL_EXPORTER_OTLP_HEADERS (the Collector's ingest token) |
All links are optional. A variable is present only while its link exists and the linked service is enabled. The mail link carries no credentials. The OpenTelemetry variables are the standard SDK settings: an application or agent that uses an OpenTelemetry SDK exports to the Collector without further configuration; set OTEL_SERVICE_NAME to name the application in traces.
Environment
WODBY_HOSTSis a JSON array of the environment's hosts, not a comma-separated string.WODBY_PRIMARY_HOSTandWODBY_PRIMARY_URLare the canonical ones for links generated outside a request.WODBY_APP_SERVICE_NAMEis this service's host name inside the environment. Other services reach the application at that name on port 8080.WODBY_ENV_TYPEtells a development environment from a production-like one.
In a development workspace
- The checkout is mounted at
/usr/src/app. The application is compiled from it and run, and the checkout is watched: when a file changes, it is compiled again and the application is restarted with the new build, in the same container, usually within a few seconds. Nothing has to be restarted or deployed for a code change. A build that fails leaves the previous build running; the compiler's errors are in the service's logs. - Workspace setup resolves dependencies with
workspace-go prepare.go.modis required. Builds use-mod=readonlyon a temporary copy ofgo.modandgo.sum, so the repository's files are never rewritten: a missing requirement or checksum fails the build and must be fixed in the repository withgo getorgo mod tidy. - The package built is
.;WORKSPACE_GO_PACKAGEon the service selects another one, such as./cmd/server. HOSTandPORTare set, to0.0.0.0and8080by default. The application must read them or listen on 8080 anyway.- A repository with a
go.workfile is refused. It needsWORKSPACE_GO_COMMANDon the service, which replaces the start command. - The compiled binary is
.wodby-workspace/appin the checkout..wodby-workspace/is kept out of Git status without touching.gitignore. - A change to variables or linked services still needs a deployment of the environment.
Check the result
curl -s -o /dev/null -w '%{http_code}' localhost:8080from the container shows whether the application answers on the expected port.go build ./... && go vet ./...in the checkout shows compile errors at once; the service's logs show them too when a change does not appear.
Обзор
Технический профиль Go
Версии
Репозиторий исходного кода
Публичный Helm-чарт
Стеки
Стеки, в которые входит Go
CI/CD
Сборка Go из Git-репозитория
Go boilerplate
Используйте его как есть или клонируйте в свой Git-аккаунт.
wodby/go-boilerplateCI-провайдеры
StackMaster CI встроен в платформу: пайплайн описывается в файле .wodby/pipeline.yml в репозитории. Для подключённого репозитория те же шаги может выполнять внешний CI-провайдер с помощью StackMaster CLI.
Реестры контейнеров
Собранные образы по умолчанию попадают в StackMaster Registry или во внешний реестр, подключённый как интеграция.
Переменные окружения из интеграций
Интеграция с переменными один раз сохраняет учётные данные стороннего сервиса. Подключите её к Go, и StackMaster передаст их в контейнер как переменные окружения во время работы, а не при сборке образа.
Конфигурация
Конфигурация сервиса Go
Технические домены
Связи сервиса
Каждая связь — это подключение Go к другому сервису. На какой сервис указывает связь, задаёт стек. На карточках перечислены публичные сервисы, которые подходят для каждой связи.
db
Сервисы, которые подходят для этой связи
sendmail
Сервисы, которые подходят для этой связи
redis
Сервисы, которые подходят для этой связи
otel
Сервисы, которые подходят для этой связи