Made configurable image registry and small improvements in the building system

This commit is contained in:
Héctor Molinero Fernández 2019-06-01 14:06:51 +02:00
parent 4767b81127
commit 7c7421f12e
4 changed files with 38 additions and 40 deletions

View File

@ -15,7 +15,7 @@ build:image:
stage: build:images stage: build:images
before_script: before_script:
- docker info - docker info
- apk add --no-cache coreutils git make - apk add --no-cache coreutils git make xz
script: script:
- make build-image save-image - make build-image save-image
artifacts: artifacts:
@ -26,8 +26,8 @@ build:image:
push:image: push:image:
stage: push:images stage: push:images
before_script: before_script:
- apk add --no-cache coreutils git make - apk add --no-cache coreutils git make xz
- docker login -u "${CI_DEPLOY_USER}" -p "${CI_DEPLOY_PASSWORD}" "${CI_REGISTRY}" >/dev/null 2>&1 - docker login -u "${CI_REGISTRY_USER}" -p "${CI_REGISTRY_PASSWORD}" "${CI_REGISTRY}" >/dev/null 2>&1
script: script:
- make load-image push-image - make load-image push-image
only: only:

View File

@ -1,4 +1,4 @@
FROM debian:sid FROM docker.io/debian:sid


# Environment # Environment
ENV QEMU_CPU=2 ENV QEMU_CPU=2

View File

@ -7,22 +7,20 @@ DOCKER := $(shell command -v docker 2>/dev/null)
GIT := $(shell command -v git 2>/dev/null) GIT := $(shell command -v git 2>/dev/null)


DISTDIR := ./dist DISTDIR := ./dist
VERSION_FILE = ./VERSION
DOCKERFILE := ./Dockerfile


IMAGE_REGISTRY := docker.io
IMAGE_NAMESPACE := hectormolinero IMAGE_NAMESPACE := hectormolinero
IMAGE_NAME := qemu-reactos IMAGE_PROJECT := qemu-reactos
IMAGE_VERSION := v0 IMAGE_NAME := $(IMAGE_REGISTRY)/$(IMAGE_NAMESPACE)/$(IMAGE_PROJECT)


# If git is available and the directory is a repository, use the latest tag as IMAGE_VERSION. IMAGE_VERSION := v0
ifeq ([$(notdir $(GIT))][$(wildcard .git/.)],[git][.git/.]) ifneq ($(wildcard $(VERSION_FILE)),)
IMAGE_VERSION := $(shell '$(GIT)' describe --abbrev=0 --tags 2>/dev/null || printf '%s' '$(IMAGE_VERSION)') IMAGE_VERSION := $(shell cat '$(VERSION_FILE)')
endif endif


IMAGE_LATEST_TAG := $(IMAGE_NAMESPACE)/$(IMAGE_NAME):latest IMAGE_TARBALL := $(DISTDIR)/$(IMAGE_PROJECT).txz
IMAGE_VERSION_TAG := $(IMAGE_NAMESPACE)/$(IMAGE_NAME):$(IMAGE_VERSION)

IMAGE_TARBALL := $(DISTDIR)/$(IMAGE_NAME).tgz

DOCKERFILE := ./Dockerfile


################################################## ##################################################
## "all" target ## "all" target
@ -38,8 +36,8 @@ all: save-image
.PHONY: build-image .PHONY: build-image
build-image: build-image:
'$(DOCKER)' build \ '$(DOCKER)' build \
--tag '$(IMAGE_VERSION_TAG)' \ --tag '$(IMAGE_NAME):$(IMAGE_VERSION)' \
--tag '$(IMAGE_LATEST_TAG)' \ --tag '$(IMAGE_NAME):latest' \
--file '$(DOCKERFILE)' ./ --file '$(DOCKERFILE)' ./


################################################## ##################################################
@ -47,7 +45,7 @@ build-image:
################################################## ##################################################


define save_image define save_image
'$(DOCKER)' save '$(1)' | gzip -n > '$(2)' '$(DOCKER)' save '$(1)' | xz -T0 > '$(2)'
endef endef


.PHONY: save-image .PHONY: save-image
@ -55,7 +53,7 @@ save-image: $(IMAGE_TARBALL)


$(IMAGE_TARBALL): build-image $(IMAGE_TARBALL): build-image
mkdir -p '$(DISTDIR)' mkdir -p '$(DISTDIR)'
$(call save_image,$(IMAGE_VERSION_TAG),$@) $(call save_image,$(IMAGE_NAME):$(IMAGE_VERSION),$@)


################################################## ##################################################
## "load-*" targets ## "load-*" targets
@ -72,7 +70,7 @@ endef
.PHONY: load-image .PHONY: load-image
load-image: load-image:
$(call load_image,$(IMAGE_TARBALL)) $(call load_image,$(IMAGE_TARBALL))
$(call tag_image,$(IMAGE_VERSION_TAG),$(IMAGE_LATEST_TAG)) $(call tag_image,$(IMAGE_NAME):$(IMAGE_VERSION),$(IMAGE_NAME):latest)


################################################## ##################################################
## "push-*" targets ## "push-*" targets
@ -84,8 +82,8 @@ endef


.PHONY: push-image .PHONY: push-image
push-image: push-image:
$(call push_image,$(IMAGE_VERSION_TAG)) $(call push_image,$(IMAGE_NAME):$(IMAGE_VERSION))
$(call push_image,$(IMAGE_LATEST_TAG)) $(call push_image,$(IMAGE_NAME):latest)


################################################## ##################################################
## "version" target ## "version" target

36
run.sh
View File

@ -3,42 +3,42 @@
set -eu set -eu
export LC_ALL=C export LC_ALL=C


DOCKER_IMAGE_NAMESPACE=hectormolinero IMAGE_NAMESPACE=hectormolinero
DOCKER_IMAGE_NAME=qemu-reactos IMAGE_PROJECT=qemu-reactos
DOCKER_IMAGE_VERSION=latest IMAGE_TAG=latest
DOCKER_IMAGE=${DOCKER_IMAGE_NAMESPACE}/${DOCKER_IMAGE_NAME}:${DOCKER_IMAGE_VERSION} IMAGE_NAME=${IMAGE_NAMESPACE}/${IMAGE_PROJECT}:${IMAGE_TAG}
DOCKER_CONTAINER=${DOCKER_IMAGE_NAME} CONTAINER_NAME=${IMAGE_PROJECT}


imageExists() { [ -n "$(docker images -q "$1")" ]; } imageExists() { [ -n "$(docker images -q "$1")" ]; }
containerExists() { docker ps -aqf name="$1" --format '{{.Names}}' | grep -Fxq "$1"; } containerExists() { docker ps -aqf name="$1" --format '{{.Names}}' | grep -Fxq "$1"; }
containerIsRunning() { docker ps -qf name="$1" --format '{{.Names}}' | grep -Fxq "$1"; } containerIsRunning() { docker ps -qf name="$1" --format '{{.Names}}' | grep -Fxq "$1"; }


if ! imageExists "${DOCKER_IMAGE}"; then if ! imageExists "${IMAGE_NAME}"; then
>&2 printf -- '%s\n' "${DOCKER_IMAGE} image doesn't exist!" >&2 printf -- '%s\n' "${IMAGE_NAME} image doesn't exist!"
exit 1 exit 1
fi fi


if containerIsRunning "${DOCKER_CONTAINER}"; then if containerIsRunning "${CONTAINER_NAME}"; then
printf -- '%s\n' "Stopping \"${DOCKER_CONTAINER}\" container..." printf -- '%s\n' "Stopping \"${CONTAINER_NAME}\" container..."
docker stop "${DOCKER_CONTAINER}" >/dev/null docker stop "${CONTAINER_NAME}" >/dev/null
fi fi


if containerExists "${DOCKER_CONTAINER}"; then if containerExists "${CONTAINER_NAME}"; then
printf -- '%s\n' "Removing \"${DOCKER_CONTAINER}\" container..." printf -- '%s\n' "Removing \"${CONTAINER_NAME}\" container..."
docker rm "${DOCKER_CONTAINER}" >/dev/null docker rm "${CONTAINER_NAME}" >/dev/null
fi fi


printf -- '%s\n' "Creating \"${DOCKER_CONTAINER}\" container..." printf -- '%s\n' "Creating \"${CONTAINER_NAME}\" container..."
docker run --detach \ docker run --detach \
--name "${DOCKER_CONTAINER}" \ --name "${CONTAINER_NAME}" \
--hostname "${DOCKER_CONTAINER}" \ --hostname "${CONTAINER_NAME}" \
--restart on-failure:3 \ --restart on-failure:3 \
--log-opt max-size=32m \ --log-opt max-size=32m \
--publish '127.0.0.1:5900:5900/tcp' \ --publish '127.0.0.1:5900:5900/tcp' \
--publish '127.0.0.1:6080:6080/tcp' \ --publish '127.0.0.1:6080:6080/tcp' \
--publish '127.0.0.1:15900:15900/tcp' \ --publish '127.0.0.1:15900:15900/tcp' \
--privileged --env QEMU_KVM=true \ --privileged --env QEMU_KVM=true \
"${DOCKER_IMAGE}" "$@" >/dev/null "${IMAGE_NAME}" "$@" >/dev/null


printf -- '%s\n\n' 'Done!' printf -- '%s\n\n' 'Done!'
exec docker logs -f "${DOCKER_CONTAINER}" exec docker logs -f "${CONTAINER_NAME}"