Skip to content

Commit

Permalink
#47: added Ubuntu-based container image
Browse files Browse the repository at this point in the history
  • Loading branch information
xelalexv committed Apr 2, 2021
1 parent ae9adb5 commit 49166ae
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 27 deletions.
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
scratchpad
_build/cache
_build/pkg
58 changes: 32 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ help:


.PHONY: release
release: clean rmi dregsy imgdregsy imgtests registryrestart tests registrydown
release: clean rmi dregsy imgdregsy imgtests tests registrydown
# clean, do an isolated build, create container images, and test
#

Expand All @@ -131,25 +131,43 @@ dregsy: prep

.PHONY: imgdregsy
imgdregsy:
# build the ${ITL}dregsy${NRM} container image; assumes binary was built
# build the ${ITL}dregsy${NRM} container images (Alpine and Ubuntu based);
# assumes binary was built
#
docker build -t xelalex/$(REPO) -f ./hack/dregsy.Dockerfile \
echo -e "\nBuilding Alpine-based image...\n"
docker build -t xelalex/$(REPO)-alpine -f ./hack/dregsy.alpine.Dockerfile \
--build-arg binaries=$(BINARIES) .
# for historical reasons, the `xelalex/dregsy` image is the Alpine image
docker tag xelalex/$(REPO)-alpine:latest xelalex/$(REPO):latest
echo -e "\n\nBuilding Ubuntu-based image...\n"
docker build -t xelalex/$(REPO)-ubuntu -f ./hack/dregsy.ubuntu.Dockerfile \
--build-arg binaries=$(BINARIES) .
echo -e "\nDone\n"


.PHONY: imgtests
imgtests:
# build the container image for running tests; assumes ${ITL}dregsy${NRM} image was built
# build the container images for running tests (Alpine and Ubuntu based);
# assumes ${ITL}dregsy-...${NRM} images were built
#
docker build -t xelalex/$(REPO)-tests -f ./hack/tests.Dockerfile .
echo -e "\nBuilding Alpine-based test image...\n"
docker build -t xelalex/$(REPO)-alpine-tests \
-f ./hack/tests.alpine.Dockerfile .
echo -e "\n\nBuilding Ubuntu-based test image...\n"
docker build -t xelalex/$(REPO)-ubuntu-tests \
-f ./hack/tests.ubuntu.Dockerfile .
echo -e "\nDone\n"


.PHONY: rmi
rmi:
# remove the ${ITL}dregsy${NRM} and testing container images
#
docker rmi -f xelalex/$(REPO)
docker rmi -f xelalex/$(REPO)-tests
docker rmi -f xelalex/$(REPO)-alpine
docker rmi -f xelalex/$(REPO)-ubuntu
docker rmi -f xelalex/$(REPO)-alpine-tests
docker rmi -f xelalex/$(REPO)-ubuntu-tests


.PHONY: tests
Expand All @@ -160,43 +178,31 @@ tests: prep
ifeq (,$(wildcard .makerc))
$(warning ***** Missing .makerc! Some tests may be skipped or fail!)
endif
@echo -e "\ntests:"
docker run --privileged --network host --rm \
-v $(shell pwd):/go/src/$(REPO) -w /go/src/$(REPO) \
-v $(shell pwd)/$(BINARIES):/go/bin \
-v /var/run/docker.sock:/var/run/docker.sock \
$(CACHE_VOLS) \
$(GCP_CREDS) \
-e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 \
-e LOG_LEVEL=debug -e LOG_FORMAT=text -e LOG_FORCE_COLORS=true \
--env-file <(sed -E 's/\ +=\ +/=/g' .makerc) \
xelalex/$(REPO)-tests sh -c "\
go test $(TEST_OPTS) \
-coverpkg=./... -coverprofile=$(BUILD_OUTPUT)/coverage.out \
-covermode=count ./... && \
go tool cover -html=$(BUILD_OUTPUT)/coverage.out \
-o $(BUILD_OUTPUT)/coverage.html"
@echo -e "\ncoverage report is in $(BUILD_OUTPUT)/coverage.html\n"
$(call utils, registry_restart)
$(call utils, run_tests alpine)
$(call utils, registry_restart)
$(call utils, run_tests ubuntu)


.PHONY: registryup
registryup:
# start local ${ITL}Docker${NRM} registry for running tests
#
docker run -d --rm -p 5000:5000 --name dregsy-test-registry registry:2
$(call utils, registry_up)


.PHONY: registrydown
registrydown:
# stop local ${ITL}Docker${NRM} registry
#
docker stop dregsy-test-registry || true
$(call utils, registry_down) || true


.PHONY: registryrestart
registryrestart: registrydown registryup
registryrestart:
# restart local ${ITL}Docker${NRM} registry
#
$(call utils, registry_restart)


.PHONY: clean
Expand Down
51 changes: 51 additions & 0 deletions hack/devenvutil
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,57 @@ function apply_shell_expansion {
eval "${command}"
}

#
#
#
function registry_up {
docker run -d --rm -p 5000:5000 --name dregsy-test-registry registry:2
}

#
#
#
function registry_down {
docker stop dregsy-test-registry
}

#
#
#
function registry_restart {
registry_down
registry_up
}

#
# $1 test image variant (`alpine` or `ubuntu`)
#
function run_tests {

echo -e "\ntesting using $1-based image:"

local root
root="$(readlink -f "$(pwd)/..")"

docker run --privileged --network host --rm \
-v "${root}:/go/src/${REPO}" -w "/go/src/${REPO}" \
-v "${root}/${BINARIES}:/go/bin" \
-v /var/run/docker.sock:/var/run/docker.sock \
${CACHE_VOLS} \
${GCP_CREDS} \
-e CGO_ENABLED=0 -e GOOS=linux -e GOARCH=amd64 \
-e LOG_LEVEL=debug -e LOG_FORMAT=text -e LOG_FORCE_COLORS=true \
--env-file <(sed -E 's/\ +=\ +/=/g' "${root}/.makerc") \
"xelalex/${REPO}-$1-tests" sh -c "\
go test ${TEST_OPTS} \
-coverpkg=./... -coverprofile=${BUILD_OUTPUT}/coverage.out \
-covermode=count ./... && \
go tool cover -html=${BUILD_OUTPUT}/coverage.out \
-o ${BUILD_OUTPUT}/coverage-$1.html"

echo -e "\ncoverage report is in ${BUILD_OUTPUT}/coverage-$1.html\n"
}

#
#
#
Expand Down
File renamed without changes.
50 changes: 50 additions & 0 deletions hack/dregsy.ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
# Copyright 2021 Alexander Vollschwitz
#
# 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
#
# 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.
#

FROM docker.io/ubuntu:20.04@sha256:c65d2b75a62135c95e2c595822af9b6f6cf0f32c11bcd4a38368d7b7c36b66f5

LABEL maintainer "vollschwitz@gmx.net"

ARG binaries

ENV DEBIAN_FRONTEND=noninteractive
ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=yes

RUN apt-get update && \
apt-get upgrade -y --fix-missing && \
apt-get install -y --no-install-recommends --fix-missing \
ca-certificates \
apt-utils \
gpg \
curl && \
echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_20.04/ /' \
> /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list && \
curl -fsSL https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_20.04/Release.key \
| gpg --dearmor > /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_stable.gpg && \
apt-get update && \
apt-get install -y --no-install-recommends --fix-missing \
skopeo=100:1.2.2-2 && \
apt-get clean -y && \
rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/*

COPY ${binaries}/dregsy /usr/local/bin

CMD ["dregsy", "-config=config.yaml"]
2 changes: 1 addition & 1 deletion hack/tests.Dockerfile → hack/tests.alpine.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#

FROM xelalex/dregsy:latest
FROM xelalex/dregsy-alpine:latest

# install & configure Go
RUN apk add --no-cache go
Expand Down
47 changes: 47 additions & 0 deletions hack/tests.ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#
# Copyright 2021 Alexander Vollschwitz
#
# 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
#
# 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.
#

FROM xelalex/dregsy-ubuntu:latest

# install & configure Go
RUN apt-get update && \
apt-get install -y --no-install-recommends --fix-missing \
golang && \
apt-get clean -y && \
rm -rf \
/var/cache/debconf/* \
/var/lib/apt/lists/* \
/var/log/* \
/tmp/* \
/var/tmp/*

ENV GOROOT /usr/lib/go
ENV GOPATH /go
ENV GOCACHE /.cache
ENV PATH /go/bin:${PATH}
RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin ${GOPATH}/pkg ${GOCACHE}

# non-root user
ARG USER=go
RUN groupadd -g ${GROUP_ID:-1000} ${USER} && \
useradd -l -u ${USER_ID:-1000} -g ${USER} ${USER} && \
install -d -m 0755 -o ${USER} -g ${USER} /home/${USER}
ENV HOME /home/${USER}
USER ${USER}

WORKDIR ${GOPATH}

CMD ["go", "version"]

0 comments on commit 49166ae

Please sign in to comment.