From b627bc492d0868827389cd4bcfd62adc35d08ea8 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Sat, 4 Nov 2017 11:17:46 +0100 Subject: [PATCH] Refit Docker build to match our current demands --- Dockerfile | 20 ++++++++++++-------- Makefile | 11 +++++++---- README.md | 28 ++++++++++++++-------------- scripts/prepare-docker-build.sh | 5 ----- 4 files changed, 33 insertions(+), 31 deletions(-) delete mode 100755 scripts/prepare-docker-build.sh diff --git a/Dockerfile b/Dockerfile index b0f1099..626d989 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,15 @@ -# This file is a template, and might need editing before it works on your project. -FROM golang:1.8-alpine AS builder -# We'll likely need to add SSL root certificates -RUN apk --no-cache add ca-certificates -# Missing part for compiling the application by it self because it requires a sock +# +# NB! This file is a template and might need editing before it works on your project! +# +FROM golang:1.8 AS builder +WORKDIR /go/src/github.com/ivanilves/lstags +COPY . ./ +RUN ln -nfs /bin/bash /bin/sh && make assemble FROM scratch -# Since we started from scratch, we'll copy the SSL root certificates from the builder +# Since we started from scratch, we'll copy following files from the builder: +# * SSL root certificates bundle COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY lstags /usr/local/bin/lstags -ENTRYPOINT [ "/usr/local/bin/lstags" ] +# * compiled lstags binary +COPY --from=builder /go/src/github.com/ivanilves/lstags/lstags /lstags +ENTRYPOINT [ "/lstags" ] CMD ["--help"] diff --git a/Makefile b/Makefile index 8324ff4..29a3511 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,8 @@ all: prepare dep test lint vet build offline: unit-test lint vet build +assemble: prepare dep lint vet build + prepare: go get -u -v \ github.com/golang/dep/cmd/dep \ @@ -69,10 +71,10 @@ shell-test-push-local: ./lstags localhost:${REGISTRY_PORT}/qa/library/alpine ${MAKE} --no-print-directory stop-local-registry -lint: ERRORS:=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i golint {} | tr '`' '|') +lint: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i golint {} | tr '`' '|') lint: fail-on-errors -vet: ERRORS:=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i go tool vet {} | tr '`' '|') +vet: ERRORS=$(shell find . -name "*.go" ! -path "./vendor/*" | xargs -i go tool vet {} | tr '`' '|') vet: fail-on-errors fail-on-errors: @@ -121,6 +123,7 @@ deploy: GITHUB_TOKEN=${GITHUB_TOKEN} ./scripts/github-create-release.sh ./dist/release GITHUB_TOKEN=${GITHUB_TOKEN} ./scripts/github-upload-assets.sh ${TAG} ./dist/assets +docker: DOCKER_REPO:=ivanilves/lstags +docker: RELEASE_TAG:=latest docker: - @docker container run -v $(shell pwd):/go/src/github.com/ivanilves/lstags -w /go/src/github.com/ivanilves/lstags -v /var/run/docker.sock:/var/run/docker.sock golang:1.8 scripts/prepare-docker-build.sh - @docker image build -t ivanilves/lstags . + @docker image build -t ${DOCKER_REPO}:${RELEASE_TAG} . diff --git a/README.md b/README.md index 7173112..e2eabad 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,11 @@ You could use `lstags`, if you ... * ... compare local images with registry ones (e.g. know, if image tagged "latest" was re-pushed). ... pull Ubuntu 14.04 & 16.04, all the Alpine images and Debian "stretch" to have latest software to play with: -``` +```sh lstags --pull ubuntu~/^1[46]\\.04$/ alpine debian~/stretch/ ``` ... pull and re-push CoreOS-related images from `quay.io` to your own registry (in case these hipsters will break everything): -``` +```sh lstags -P /quay -r registry.company.io quay.io/coreos/hyperkube quay.io/coreos/flannel ``` **NB!** In case you use private registry with authentication, make sure your Docker client knows how to authenticate against it! @@ -59,7 +59,7 @@ You can either: https://github.com/ivanilves/lstags/releases ## Install: From source -``` +```sh git clone git@github.com:ivanilves/lstags.git cd lstags dep ensure @@ -68,9 +68,9 @@ go build ``` **NB!** I assume you have current versions of Go & [dep](https://github.com/golang/dep) installed and also have set up [GOPATH](https://github.com/golang/go/wiki/GOPATH) correctly. -## Using it with docker +## Using it with Docker -```sh +``` docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock ivanilves/lstags Usage: lstags [OPTIONS] REPO1 REPO2 REPOn... @@ -108,17 +108,17 @@ Arguments: ### Analyze an image -```sh -docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock ivanilves/lstags alpine~/^3\\./ +``` +docker run --rm -it -v /var/run/docker.sock:/var/run/docker.sock ivanilves/lstags alpine~/^3\\./ ANALYZE alpine FETCHED alpine - - <(local) ID> -CHANGED sha256:b40e202395eaec699f2d0c5e01e6d6cb8 76da55c8019d 2017-10-25T23:19:51Z alpine:3.6 -ABSENT sha256:d95da16498d5d6fb4b907cbe013f95032 n/a 2017-10-25T23:20:18Z alpine:3.1 -ABSENT sha256:cb275b62f789b211114f28b391fca3cc2 n/a 2017-10-25T23:20:32Z alpine:3.2 -ABSENT sha256:27af7da847283a947c008592f2b2cd6d2 n/a 2017-10-25T23:20:45Z alpine:3.3 -CHANGED sha256:246bbbaa81b28837b64cb9dfc574de958 1a19a71e5d38 2017-10-25T23:20:59Z alpine:3.4 -CHANGED sha256:aa96c8dc3815c44d4aceaf1ee7903ce58 37c7be7a096b 2017-10-25T23:21:13Z alpine:3.5 + <(local) ID> +CHANGED sha256:b40e202395eaec699f2d0c5e01e6d6cb8 76da55c8019d 2017-10-25T23:19:51Z alpine:3.6 +ABSENT sha256:d95da16498d5d6fb4b907cbe013f95032 n/a 2017-10-25T23:20:18Z alpine:3.1 +ABSENT sha256:cb275b62f789b211114f28b391fca3cc2 n/a 2017-10-25T23:20:32Z alpine:3.2 +ABSENT sha256:27af7da847283a947c008592f2b2cd6d2 n/a 2017-10-25T23:20:45Z alpine:3.3 +CHANGED sha256:246bbbaa81b28837b64cb9dfc574de958 1a19a71e5d38 2017-10-25T23:20:59Z alpine:3.4 +CHANGED sha256:aa96c8dc3815c44d4aceaf1ee7903ce58 37c7be7a096b 2017-10-25T23:21:13Z alpine:3.5 - ``` diff --git a/scripts/prepare-docker-build.sh b/scripts/prepare-docker-build.sh deleted file mode 100755 index 730d43b..0000000 --- a/scripts/prepare-docker-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -# Workaround because the Makefile doesn't recognize the bash -# This should be fixed in the Makefile and not in the directory -ln -nfs /bin/bash /bin/sh -make all