Automating version pick-up according to current git version and minor Kustomize hotfixes (#135)

This commit is contained in:
Dario Tranchitella
2020-11-17 19:20:31 +01:00
committed by GitHub
parent 45709f7bd3
commit 6541f19b67
7 changed files with 39 additions and 15 deletions
+3 -1
View File
@@ -33,7 +33,9 @@ jobs:
k8s-version: ['v1.16.15', 'v1.17.11', 'v1.18.8', 'v1.19.1']
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@master
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Cache Go modules and Docker images
uses: actions/cache@v1
env:
+14 -4
View File
@@ -11,15 +11,25 @@ RUN go mod download
# Copy the go source
COPY main.go main.go
COPY version.go version.go
COPY api/ api/
COPY controllers/ controllers/
COPY pkg/ pkg/
COPY version/ version/
ARG VERSION
COPY .git .git
# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -ldflags "-X github.com/clastix/capsule/version.Version=${VERSION}" -o manager main.go
RUN git config --get remote.origin.url > /tmp/GIT_REPO && \
git rev-parse --short HEAD > /tmp/GIT_HEAD_COMMIT && \
git describe --abbrev=0 --tags > /tmp/GIT_LAST_TAG && \
git rev-parse --short $(cat /tmp/GIT_LAST_TAG) > /tmp/GIT_TAG_COMMIT && \
git diff $(cat /tmp/GIT_HEAD_COMMIT) $(cat /tmp/GIT_TAG_COMMIT) --quiet > /tmp/GIT_MODIFIED1 || echo '.dev' > /tmp/GIT_MODIFIED1 && \
git diff --quiet > /tmp/GIT_MODIFIED2 || echo '.dirty' > /tmp/GIT_MODIFIED2 && \
cat /tmp/GIT_MODIFIED1 /tmp/GIT_MODIFIED2 | tr -d '\n' > /tmp/GIT_MODIFIED && \
date '+%Y-%m-%dT%H:%M:%S' > /tmp/BUILD_DATE &&\
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build \
-gcflags "-N -l" \
-ldflags "-X main.GitRepo=$(cat /tmp/GIT_REPO) -X main.GitTag=$(cat /tmp/GIT_LAST_TAG) -X main.GitCommit=$(cat /tmp/GIT_HEAD_COMMIT) -X main.GitDirty=$(cat /tmp/GIT_MODIFIED) -X main.BuildTime=$(cat /tmp/BUILD_DATE)" \
-o manager
# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
+2 -2
View File
@@ -1,5 +1,5 @@
# Current Operator version
VERSION ?= 0.0.1
VERSION ?= $$(git describe --abbrev=0 --tags)
# Default bundle image tag
BUNDLE_IMG ?= quay.io/clastix/capsule:$(VERSION)-bundle
@@ -75,7 +75,7 @@ generate: controller-gen
# Build the docker image
docker-build: test
docker build . --build-arg=VERSION=${VERSION} -t ${IMG}
docker build . -t ${IMG}
# Push the docker image
docker-push:
+1 -3
View File
@@ -5,6 +5,4 @@ kind: Kustomization
images:
- name: controller
newName: quay.io/clastix/capsule
newTag: 0.0.1
- name: quay.io/clastix/capsule
newTag: 0.0.1
newTag: v0.0.2
+1 -1
View File
@@ -34,7 +34,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: quay.io/clastix/capsule:latest
image: controller
imagePullPolicy: IfNotPresent
name: manager
resources:
+3 -2
View File
@@ -47,7 +47,6 @@ import (
"github.com/clastix/capsule/pkg/webhook/tenant"
"github.com/clastix/capsule/pkg/webhook/tenant_prefix"
"github.com/clastix/capsule/pkg/webhook/utils"
"github.com/clastix/capsule/version"
// +kubebuilder:scaffold:imports
)
@@ -64,7 +63,9 @@ func init() {
}
func printVersion() {
setupLog.Info(fmt.Sprintf("Operator Version: %s", version.Version))
setupLog.Info(fmt.Sprintf("Capsule Version %s %s%s", GitTag, GitCommit, GitDirty))
setupLog.Info(fmt.Sprintf("Build from: %s", GitRepo))
setupLog.Info(fmt.Sprintf("Build date: %s", BuildTime))
setupLog.Info(fmt.Sprintf("Go Version: %s", goRuntime.Version()))
setupLog.Info(fmt.Sprintf("Go OS/Arch: %s/%s", goRuntime.GOOS, goRuntime.GOARCH))
}
+15 -2
View File
@@ -14,6 +14,19 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
package version
package main
var Version = "dev"
//GitRepo ...
var GitRepo = ""
//GitTag ...
var GitTag = "dev"
//GitCommit ...
var GitCommit = ""
//GitDirty ...
var GitDirty = "dirty"
//BuildTime ...
var BuildTime = ""