Go
How Build and Deploy Golang project?
If you do not have code ready, you can fork the repository being used in this example: https://github.com/paladium/nativeci-demos
Guide
First you would need to choose one of golang projects available, if you do not have one, you can navigate to this example to deploy a project Create project example.
At the last page, let's explore all the options available and common deployment commands you can use.
Build command examples:
#Will build main file and name the binary main
go build -o main main.go
#Reduce binary size by stripping runtime information
go build -ldflags="-s -w" -o main main.go
#Build into deployment folder
go build -o deployment/main main.go
Folder examples:
#Leave empty for repos with only one project
#For multiple projects in repo can choose the folder to build
backend
api
Web service/port to expose examples:
#Any integer number
8080
8000
3000
Deploy folder examples:
#If deployment folder used
deployment
Run command examples:
#Can provide config path:
./main config.yaml
#Can provide port
./main --port=8080
Using these settings, you can deploy most of the golang based applications. However if you need more customisations, you can always choose
Dockerfile
language. Here is the starter template for golang-based projects:
FROM golang:1.18-buster AS build
WORKDIR /app
COPY go.mod ./
COPY go.sum ./
RUN go mod download
COPY *.go ./
RUN go build -o /main
## Deploy
FROM gcr.io/distroless/base-debian10
WORKDIR /
COPY /main /main
EXPOSE 8080
USER nonroot:nonroot
ENTRYPOINT ["/main"]