65 lines
1.9 KiB
YAML
65 lines
1.9 KiB
YAML
steps:
|
|
# Builds your Go application
|
|
build:
|
|
# Set your preferred Go version:
|
|
image: golang:1.17
|
|
environment:
|
|
# Needed if you want to cross-compile and package the binary in a container.
|
|
- CGO_ENABLED=0
|
|
# Select your target OS:
|
|
- GOOS=linux
|
|
# Select your target architecture:
|
|
- GOARCH=amd64
|
|
commands:
|
|
- go get
|
|
- go build -o {{.ExecutableName}}
|
|
|
|
# Runs a dryrun to build the docker container
|
|
dryrun-docker:
|
|
image: plugins/kaniko
|
|
settings:
|
|
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
|
tags: test
|
|
dockerfile: Dockerfile
|
|
# Just builds the container without a push to DockerHub.
|
|
no_push: true
|
|
when:
|
|
event: pull_request
|
|
|
|
# Builds and publishes a docker container to DockerHub from the main-branch
|
|
publish-docker-latest:
|
|
image: plugins/kaniko
|
|
settings:
|
|
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
|
tags: latest
|
|
dockerfile: Dockerfile
|
|
username:
|
|
# Secret 'docker_username' needs to be set in the CI settings
|
|
from_secret: docker_username
|
|
password:
|
|
# Secret 'docker_password' needs to be set in the CI settings
|
|
from_secret: docker_password
|
|
when:
|
|
# Push new version of tag latest if new push on main-branch
|
|
event: push
|
|
branch: main
|
|
|
|
# Builds and publishes a docker container of a tag
|
|
publish-docker-tag:
|
|
image: plugins/kaniko
|
|
settings:
|
|
repo: DOCKERUSERNAME/DOCKERHUBREPO
|
|
# Uses the tag from git for the container tag
|
|
tags: ${CI_COMMIT_TAG}
|
|
dockerfile: Dockerfile
|
|
username:
|
|
# Secret 'docker_username' needs to be set in the CI settings
|
|
from_secret: docker_username
|
|
password:
|
|
# Secret 'docker_password' needs to be set in the CI settings
|
|
from_secret: docker_password
|
|
when:
|
|
# Push new version when version tag is created
|
|
event: tag
|
|
ref: refs/tags/v*
|