-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Script tool installation and linting #85
Conversation
898d44d
to
a91d08d
Compare
I noticed that the second docker build (to extract the profiling data) was not caching any image layers from the first build. Restructured the build script a bit to fix that. |
scripts/install-go-tools.sh
Outdated
return | ||
fi | ||
|
||
echo "Installing gometalinter. Version: ${GLMVER}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: GLMVER ==> GMLVER
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -11,25 +11,42 @@ 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')" | |||
|
|||
GO_DEP_VERSION="${GO_DEP_VERSION}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: ${GO_DEP_VERSION:-latest}
It took me a while to track down where the dep version was actually set. It would be good to put it here w/ the other defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting it to latest
breaks the script. It expects either a version tag or empty string (as latest).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can see that here, https://github.com/gluster/gluster-csi-driver/pull/85/files#diff-b6e2d673cd08c78537e77f91e9e2272aR11, at the version check. Not ideal, but 🤷♂️
@@ -11,25 +11,42 @@ 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')" | |||
|
|||
GO_DEP_VERSION="${GO_DEP_VERSION}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I can see that here, https://github.com/gluster/gluster-csi-driver/pull/85/files#diff-b6e2d673cd08c78537e77f91e9e2272aR11, at the version check. Not ideal, but 🤷♂️
@humblec PTAL |
@@ -11,25 +11,42 @@ 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')" | |||
|
|||
GO_DEP_VERSION="${GO_DEP_VERSION}" | |||
GO_METALINTER_VERSION="${GO_METALINTER_VERSION:-v2.0.11}" | |||
GO_METALINTER_THREADS=${GO_METALINTER_THREADS:-4} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the deafult thread count ?
GOPACKAGES="$(go list ./... | grep -v vendor | grep -v e2e)"; \ | ||
go test -covermode=count -coverprofile=/profile.cov $GOPACKAGES; \ | ||
} | ||
ARG GO_METALINTER_THREADS=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the threads has been set to 1
and above on 4
. Any specific reason for these 2 values ?
pkg/glusterfs/Dockerfile
Outdated
|
||
# Build executable | ||
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"' -o /glusterfs-csi-driver cmd/glusterfs/main.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Output binary and source path can be variables.
The GML default is "1", and I try to preserve defaults in the Dockerfile where possible. For our purposes, we've alwayd been running it with a thread count of 4, so I set that as the default in the build script.
Agreed, can do. |
460832f
to
96f6550
Compare
@Madhu-1 @JohnStrunk any further comments ? |
pkg/glusterfs/Dockerfile
Outdated
@@ -10,55 +10,60 @@ | |||
# See the License for the specific language governing permissions and | |||
# limitations under the License. | |||
|
|||
# The base image to use for the final images | |||
ARG FINAL_BASE=centos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this still build w/ buildah bud
? I suspect this line and the construct on L56 will break it due to bugs/missing features.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't tried. Any instructions on how to do that? Is it just run buildah bud
from the root of the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's basically a replacement for docker build: docker build <stuff>
==> buildah bud <stuff>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So i should be able to test it by setting DOCKER_CMD="buildah bud"
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not quite that easy. That would produce buildah bud build <stuff>
. You need to replace both "docker" and "build" parts of the command line. The other "stuff" should transfer as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like your original change already broke buildah, as it doesn't recognize --target
. Should I try refactoring all this so that buildah runs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... we need to keep buildah working. Of course I'm not sure how we're going to get the coverage data out w/o being able to refer to the intermediate image or splitting into multiple dockerfiles. And having multiple dockerfiles will prevent us from autobuilding on docker hub.
For now, I suppose pulling it forward into the final image then copying it out is good enough... it's small.
BTW, a quick search turned up the bug in buildah: containers/buildah#632
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I'm running into a no build container available
error that I can't find any diagnosis for online. Ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jarrpa is above issue resolved at ur end ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah. Had to add docker.io
to the base image names.
@JohnStrunk Added a commit to adjust my changes for buildah compatibility. PTAL |
pkg/glusterfs/Dockerfile
Outdated
|
||
#-- Build phase | ||
FROM openshift/origin-release:golang-1.10 AS build | ||
FROM docker.io/openshift/origin-release:golang-1.10 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FROM ... AS is supported. The following works for me:
$ cat Dockerfile
FROM centos:7.5.1804 as base
RUN echo "hello" > /h
FROM centos:7.5.1804 as final
COPY --from=base /h /h
RUN cat /h
with
$ buildah bud .
STEP 1: FROM centos:7.5.1804
Getting image source signatures
Copying blob sha256:7dc0dca2b1516961d6b3200564049db0a6e0410b370bb2189e2efae0d368616f
71.23 MiB / 71.23 MiB [===================================================] 19s
Copying config sha256:76d6bc25b8a5685072a1a99d9ac7c2e52dc3070081c872034a1889ca2d4bcf8c
2.15 KiB / 2.15 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
STEP 2: RUN echo "hello" > /h
STEP 3: FROM centos:7.5.1804
STEP 4: COPY --from=base /h /h
STEP 5: RUN cat /h
hello
STEP 6: COMMIT containers-storage:[vfs@/home/jstrunk/.local/share/containers/storage+/run/user/101587/run]@4a5769081c038b6ed9e8fe400078d068e773c6ed048ff485e648c2f1985113c2
Getting image source signatures
Skipping fetch of repeat blob sha256:bcc97fbfc9e1a709f0eb78c1da59caeb65f43dc32cd5deeb12b8c1784e5b8237
Copying blob sha256:34e18c749bcf5457f2a2d4d36a3a0fce5e04f723c81be2dc38f37835256dbf27
169 B / 169 B [============================================================] 0s
Copying config sha256:fcf270bec64248fd75cbe464ce99bfc0229c56ba2fdb7894a100532a97fd07cd
1.18 KiB / 1.18 KiB [======================================================] 0s
Writing manifest to image destination
Storing signatures
--> 4a5769081c038b6ed9e8fe400078d068e773c6ed048ff485e648c2f1985113c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. I didn't see the point of keeping it if we're not making meaningful use of it, but I'll add it back in.
Previously, the second docker build would not actually use any images from the docker cache. If testing, build and tag the build container first, then build the final container. If not testing, only build once. Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Move the linting and test commands out into of the Dockerfile into scripts, using some existing scripting in the repo. This makes the Dockerfile cleaner and allows the commands to be run outside the container build for development purposes. Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
Signed-off-by: Jose A. Rivera <jarrpa@redhat.com>
@JohnStrunk Updated per comments and to allow the CI to pass (needed to override the container entrypoint). PTAL |
RUN CGO_ENABLED=0 GOOS=linux go build -ldflags '-extldflags "-static"' -o /build/glusterfs-csi-driver cmd/glusterfs/main.go | ||
|
||
# Ensure the binary is statically linked | ||
RUN ldd /build/glusterfs-csi-driver | grep -q "not a dynamic executable" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the benefit of this validation ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I didn't add it. Just keeping what was already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It guarantees the generated binary is statically linked, so there are no library dependencies that would need to be pulled into the final image.
|
||
#-- Final container | ||
FROM centos:7.5.1804 | ||
|
||
FROM docker.io/centos:7.5.1804 as final |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why cant we use latest
tag here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I didn't add it. Just keeping what was already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because if you use latest, you don't get a repeatable container image.
Also |
I don't think pre-commit looks better. It's vague and does not describe what the script does. It made sense when there were more things in it, but now it only does one thing, generally. Other things like the go linting would also technically count as "pre-commit" actions, but have always been in their own files. |
This is good to go. @JohnStrunk @Madhu-1 any final comments ? |
Move the linting and test commands out into of the Dockerfile into
scripts, using some existing scripting in the repo. This makes the
Dockerfile cleaner and allows the commands to be run outside the
container build for development purposes.
Signed-off-by: Jose A. Rivera jarrpa@redhat.com