It supports:
- Golang dep manager (dep is a prototype dependency management tool) - /example-golang-dep
- glide manager - /example-glide
- godep manager - /example-godep
- govendor manager - /example-govendor
- Traditional
go get
- /example
Data | Value |
---|---|
Go | Go v1.9.2 |
OpenShift | OpenShift Origin v1.5 |
Git repository | https://github.com/amsokol/openshift-golang-template.git |
Context directory | /example-golang-dep |
Folder with main.go to build and run | /example-golang-dep/cmd/server |
- Login with Developer account to OpenShift:
# oc login --insecure-skip-tls-verify -u <username> https://openshift.example.com:8443
- Create new project:
# oc new-project project1
- Select
project1
project:
# oc project project1
- Create ImageStream:
# oc create -f ./openshift-golang-template.yaml
-
Login to OpenShift console using browser (e.g. https://openshift.example.com:8443) with Developer account
-
Open
project1
project -
Click
Add to Project
and selectGo
-
Select
1.9.2 - latest
from drop down list and clickSelect
-
Set
Name
togolang1
-
Set
Git Repository URL
tohttps://github.com/amsokol/openshift-golang-template.git
or clickTry It
-
Click
advanced options
to add additional configuration parameters -
Set
Context Dir
to/example-golang-dep
(sample project with dep manager support) -
Add the following environment variables to
Build Configuration
section:
- GOPROJECT_ROOT=github.com/amsokol/openshift-golang-template/example-golang-dep
- GOPROJECT_CMD=cmd/server
GOPROJECT_ROOT tells builder the root package of go project
GOPROJECT_CMD tells builder the where "main()" function of "main" package to build and run is located (relative to GOPROJECT_ROOT).
Note: ignore GOPROJECT_CMD if "main()" function of "main" package is located in GOPROJECT_ROOT folder.
In example above "main()" function of "main" package is located in `github.com/amsokol/openshift-golang-template/example-golang-dep/cmd/server`.
GOPROJECT_ROOT is set to `github.com/amsokol/openshift-golang-template/example-golang-dep`.
So GOPROJECT_CMD is set to `cmd/server`
- [Optional] You can easy provide
go build
arguments. Just addGO_BUILD_ARGS
environment variable toBuild Configuration
section. For example the following value tellsgo build
to print the commands are run and packages are compiled:
GO_BUILD_ARGS=-x -v
Note: please DO NOT override output file name ("-o" argument)!
- [Optional] You can easy provide command line arguments to your binary. Just add
GOPROJECT_CMD_ARGS
environment variable toDeployment Configuration
section. For example the following value provides--silent
and--force
arguments the binary:
GOPROJECT_CMD_ARGS=--silent --force
- [Optional] You can easy provide configuration files to your binary that are copied by the build script to
GOPATH\bin
(where your binary file is located). Just addGOPROJECT_CMD_CONFIG
,GOPROJECT_CMD_CONFIG1
,GOPROJECT_CMD_CONFIG2
,GOPROJECT_CMD_CONFIG3
, etc. environment variables toBuild Configuration
section. If your configuration files are located in the same project source control repositoryGOPROJECT_CMD_CONFIGx
values should beGOPROJECT_ROOT
related path. But you need to know that store configuration files into project repository is BAD PRACTICES (configuration files usually contain credentials, IPs, etc.). It's much more better to inject configuration file from outside (e.g. download from CI server). In this case setGOPROJECT_CMD_CONFIGx
by URL value. Build scripts runscurl
utility to download configuration files. It supports:
DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet, TFTP, SSL certificates, proxies, HTTP/2, cookies, user+password authentication (Basic, Plain, Digest, CRAM-MD5, NTLM, Negotiate and Kerberos) and more.
Here are some examples:
Provide configuration file is stored into the same source code repository (not recommended for production):
GOPROJECT_CMD_CONFIG=config/settings.yaml
Provide configuration files are stored into the same source code repository (not recommended for production):
GOPROJECT_CMD_CONFIG1=config/db/db.yaml
GOPROJECT_CMD_CONFIG2=config/messaging/broker.json
Download configuration file via HTTPS:
GOPROJECT_CMD_CONFIG=https://config.server.com/myapp/settings.yaml
Download configuration files via HTTPS:
GOPROJECT_CMD_CONFIG1=https://config.server.com/myapp/db/db.yaml
GOPROJECT_CMD_CONFIG2=smb://config.server.com/messaging/broker.json -u "domain\username:passwd"
Notes:
- If you have only one configuration file use
GOPROJECT_CMD_CONFIG
environment variable. If you have more that one configuration files useGOPROJECT_CMD_CONFIG1
,GOPROJECT_CMD_CONFIG2
,GOPROJECT_CMD_CONFIG3
, etc. environment variables. - As you see above you can provide not URL only but other
curl
arguments like credentials. It very important to pass arguments after URL:
Correct:
GOPROJECT_CMD_CONFIG=smb://config.server.com/messaging/broker.json -u "domain\username:passwd"
Wrong:
GOPROJECT_CMD_CONFIG=-u "domain\username:passwd" smb://config.server.com/messaging/broker.json
- Leave other options with default values and click
Create
and wait while pod is created
-
Login to OpenShift console using browser (eg https://openshift.example.com:8443) with Developer account
-
Open
project1
project -
Click
Applications -> Deployments
-
Click
golang1
in the list -
Select
Configuration
tab -
Click
Add Health Checks
-
Click
Add Readiness Probe
-
Set
Path
to '/healthz/ready' and leave other options with default values -
Click
Add Liveness Probe
-
Set
Path
to '/healthz/live' and leave other options with default values -
Click
Save
and wait while pod is created
s2i build https://github.com/amsokol/openshift-golang-template.git amsokol/golang-openshift:1.9.2-1 golang1 -e GOPROJECT_ROOT=github.com/amsokol/openshift-golang-template/example-golang-dep -e GOPROJECT_CMD=cmd/server --context-dir /example-golang-dep
-
Login using oc as OpenShift administrator
-
Run:
# oc get templates -n openshift
# oc edit template -n openshift nodejs-mongo-persistent