-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from JohnStrunk/36-multi-stage-docker
Fully containerized build
- Loading branch information
Showing
11 changed files
with
136 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.git | ||
vendor | ||
profile.cov |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#! /bin/bash | ||
|
||
set -e | ||
|
||
# Allow overriding default docker command | ||
DOCKER_CMD=${DOCKER_CMD:-docker} | ||
|
||
# Allow disabling tests during build | ||
RUN_TESTS=${RUN_TESTS:-1} | ||
|
||
VERSION="$(git describe --dirty --always --tags | sed 's/-/./2' | sed 's/-/./2')" | ||
BUILDDATE="$(date -u '+%Y-%m-%dT%H:%M:%S.%NZ')" | ||
|
||
#-- Build final container | ||
$DOCKER_CMD build \ | ||
-t glusterfs-csi-driver \ | ||
--build-arg RUN_TESTS="$RUN_TESTS" \ | ||
--build-arg version="$VERSION" \ | ||
--build-arg builddate="$BUILDDATE" \ | ||
-f pkg/glusterfs/Dockerfile \ | ||
. \ | ||
|| exit 1 | ||
|
||
if [ "$RUN_TESTS" -ne 0 ]; then | ||
rm -f profile.cov | ||
$DOCKER_CMD build \ | ||
-t glusterfs-csi-driver-build \ | ||
--target build \ | ||
--build-arg RUN_TESTS="$RUN_TESTS" \ | ||
-f pkg/glusterfs/Dockerfile \ | ||
. \ | ||
&& \ | ||
$DOCKER_CMD run --rm glusterfs-csi-driver-build \ | ||
cat /profile.cov > profile.cov | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,87 @@ | ||
# Copyright 2018 The Gluster CSI Authors. | ||
|
||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
#You may obtain a copy of the License at | ||
|
||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Licensed under GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 | ||
# You may obtain a copy of the License at | ||
# https://opensource.org/licenses/lgpl-3.0.html | ||
|
||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
#-- Build phase | ||
FROM openshift/origin-release:golang-1.10 AS build | ||
|
||
ENV GOPATH="/go/" \ | ||
SRCDIR="/go/src/github.com/gluster/gluster-csi-driver/" | ||
|
||
RUN yum install -y \ | ||
git | ||
|
||
# Install dep | ||
RUN mkdir -p /go/bin | ||
RUN curl -L https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
|
||
# Install gometalinter | ||
ARG GO_METALINTER_VERSION=v2.0.11 | ||
RUN curl -L 'https://raw.githubusercontent.com/alecthomas/gometalinter/master/scripts/install.sh' \ | ||
| bash -s -- -b "${GOPATH}bin" "${GO_METALINTER_VERSION}" | ||
|
||
# Vendor dependencies | ||
COPY Gopkg.lock Gopkg.toml "${SRCDIR}" | ||
WORKDIR "${SRCDIR}" | ||
RUN /go/bin/dep ensure -v -vendor-only | ||
|
||
# Build executable | ||
COPY . "${SRCDIR}" | ||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"' -o /glusterfs-csi-driver cmd/glusterfs/main.go | ||
|
||
# Ensure the binary is statically linked | ||
RUN ldd /glusterfs-csi-driver | grep -q "not a dynamic executable" | ||
|
||
# Run tests | ||
ARG RUN_TESTS=1 | ||
RUN [ $RUN_TESTS -eq 0 ] || { \ | ||
set -o pipefail \ | ||
&& gometalinter -j4 --sort=path --sort=line --sort=column \ | ||
--enable="gofmt" \ | ||
--exclude="method NodeGetId should be NodeGetID" \ | ||
--deadline 9m --vendor --debug ./... \ | ||
|& stdbuf -oL awk '/linter took/ || !/^DEBUG/'; \ | ||
} | ||
RUN [ $RUN_TESTS -eq 0 ] || { \ | ||
GOPACKAGES="$(go list ./... | grep -v vendor | grep -v e2e)"; \ | ||
go test -covermode=count -coverprofile=/profile.cov $GOPACKAGES; \ | ||
} | ||
|
||
|
||
#-- Final container | ||
FROM centos:7.5.1804 | ||
|
||
# Copy glusterfs-csi-driver from build directory | ||
COPY ./build/glusterfs-csi-driver /glusterfs-csi-driver | ||
# Install dependencies | ||
RUN yum -y install centos-release-gluster && \ | ||
yum -y install glusterfs-fuse && \ | ||
yum clean all -y && \ | ||
rm -rf /var/cache/yum && \ | ||
rpm -qa | grep gluster | tee /gluster-rpm-versions.txt | ||
|
||
# Copy glusterfs-csi-driver from build phase | ||
COPY --from=build /glusterfs-csi-driver /glusterfs-csi-driver | ||
|
||
# The version of the driver (git describe --dirty --always --tags | sed 's/-/./2' | sed 's/-/./2') | ||
ARG version="(unknown)" | ||
# Container build time (date -u '+%Y-%m-%dT%H:%M:%S.%NZ') | ||
ARG builddate="(unknown)" | ||
|
||
RUN yum -y install glusterfs-fuse && yum clean all -y | ||
LABEL build-date="${builddate}" | ||
LABEL io.k8s.description="FUSE-based CSI driver for Gluster file access" | ||
LABEL name="glusterfs-csi-driver" | ||
LABEL Summary="FUSE-based CSI driver for Gluster file access" | ||
LABEL vcs-type="git" | ||
LABEL vcs-url="https://github.com/gluster/gluster-csi-driver" | ||
LABEL vendor="gluster.org" | ||
LABEL version="${version}" | ||
|
||
ENTRYPOINT ["/glusterfs-csi-driver"] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters