Commit 706b87ff authored by Marcel Huber's avatar Marcel Huber
Browse files

simplified build

parent b04a8465
Pipeline #8310 passed with stages
in 2 minutes and 29 seconds
image: docker:latest
variables:
MY_IMAGE_NAME: "COAST build tools image"
MY_BUILT_IMAGE: $CI_REGISTRY_IMAGE:coastbuild
MY_DOCKER_IMAGE: marcelhuberfoo/arch-build-coast
MY_DOCKER_FILE: Dockerfile
MY_DOCKER_CONTEXT: .
IMAGE_NAME: "COAST build tools image"
LOCAL_IMAGE: $CI_REGISTRY_IMAGE/arch-build-coast
LOCAL_IMAGE_TAG: $CI_REGISTRY_IMAGE/arch-build-coast:$CI_COMMIT_REF_NAME
REMOTE_IMAGE: marcelhuberfoo/arch-build-coast
stages:
- build
- test
- deploy
before_script:
build:
BuildImage:
stage: build
tags:
- docker
script:
- apk --no-cache --quiet add git
- ./build.sh
- docker build --no-cache
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
--label org.label-schema.name="$IMAGE_NAME"
--label org.label-schema.url="$CI_PROJECT_URL"
--label org.label-schema.schema-version="1.0"
--label org.label-schema.vcs-ref="$CI_COMMIT_SHA"
--label org.label-schema.vcs-url="$(echo $CI_REPOSITORY_URL | sed 's|gitlab-ci-token[^@]*@||')"
--label org.label-schema.vendor="me"
--label org.label-schema.version="$CI_COMMIT_REF_NAME"
--tag=$LOCAL_IMAGE_TAG
--file=Dockerfile
.
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $MY_BUILT_IMAGE
- docker push $LOCAL_IMAGE_TAG
test:
TestImage:
stage: test
tags:
- docker
script:
- docker run --rm $MY_BUILT_IMAGE python2 -V
- docker run --rm $LOCAL_IMAGE_TAG python2 -V
deploy:
TagImage:
stage: deploy
tags:
- docker
only:
- tags
- triggers
tags:
- docker
script:
- apk --no-cache --quiet add curl
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $MY_BUILT_IMAGE
- docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
- docker tag ${MY_BUILT_IMAGE} ${MY_DOCKER_IMAGE}:latest
- docker tag ${MY_BUILT_IMAGE} ${MY_DOCKER_IMAGE}:$(docker run --rm --entrypoint /bin/sh $MY_DOCKER_IMAGE -c 'echo -n ${BUILD_TAG}')
- docker push ${MY_DOCKER_IMAGE}:latest
- docker push ${MY_DOCKER_IMAGE}:$(docker run --rm --entrypoint /bin/sh $MY_DOCKER_IMAGE -c 'echo -n ${BUILD_TAG}')
- if [ -n "$MICROBADGER_UPDATE_HOOK" ]; then curl --silent --request POST $MICROBADGER_UPDATE_HOOK; fi
- if [ -n "$TRIGGER_URL" ]; then curl --silent --request POST --form token=$TRIGGER_TOKEN --form ref=master $TRIGGER_URL; fi
- docker image tag $LOCAL_IMAGE_TAG $LOCAL_IMAGE:$CI_COMMIT_TAG
- test -n "$DOCKER_USER" && {
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS";
docker tag $LOCAL_IMAGE_TAG $REMOTE_IMAGE:latest;
docker tag $LOCAL_IMAGE_TAG $REMOTE_IMAGE:$CI_COMMIT_TAG;
docker push $REMOTE_IMAGE:latest;
docker push $REMOTE_IMAGE:$CI_COMMIT_TAG;
} || true
- test -n "$MICROBADGER_UPDATE_HOOK" && {
apk --no-cache add curl;
curl --silent --request POST $MICROBADGER_UPDATE_HOOK;
} || true
- test -n "$TRIGGER_URL" && {
apk --no-cache add curl;
curl --silent --request POST --form token=$TRIGGER_TOKEN --form ref=master $TRIGGER_URL;
} || true
FROM marcelhuberfoo/arch-build
MAINTAINER Marcel Huber <marcelhuberfoo@gmail.com>
ARG BUILD_TIME
ARG BUILD_DATE
ARG BUILD_TAG
ARG MY_IMAGE_NAME
ARG MY_DOCKER_FILE
ARG CI_PROJECT_URL
ARG VCS_REF
ARG VCS_URL
LABEL org.label-schema.build-date="$BUILD_TIME" \
org.label-schema.docker.dockerfile="$MY_DOCKER_FILE" \
org.label-schema.name="$MY_IMAGE_NAME" \
org.label-schema.url="$CI_PROJECT_URL" \
org.label-schema.vcs-ref="$VCS_REF" \
org.label-schema.vcs-url="$VCS_URL" \
org.label-schema.version="$BUILD_TAG" \
org.label-schema.schema-version="1.0"
ENV BUILD_DATE=$BUILD_DATE
ENV BUILD_TAG=$BUILD_TAG
USER root
RUN sh -ec 'pacman -Syyu --noconfirm --quiet --noprogressbar --needed \
......
#!/bin/sh
_BUILD_TAG="$(git describe --abbrev=0 --tags 2>/dev/null)"
_VCS_URL="$(echo $CI_REPOSITORY_URL | sed 's|gitlab-ci-token[^@]*@||')"
_CI_PROJECT_URL="${CI_PROJECT_URL:-https://gitlab.dev.ifs.hsr.ch/}"
if [ -n "$_BUILD_TAG" ]; then
_revs_ahead_tag=$(git rev-list --count ${_BUILD_TAG}..)
_commit_id_short=$(git log -1 --format=%h)
_VCS_REF="$(echo $_BUILD_TAG | sed -e 's/^[-_/a-zA-Z]\+//' -e 's/[-_+]/./g').${_revs_ahead_tag}.g${_commit_id_short}"
else
_VCS_REF="0.$(git rev-list --count ${CI_COMMIT_SHA_NAME:-master}).g$(git log -1 --format=%h)"
fi
set -e
docker build --no-cache \
--build-arg MY_DOCKER_FILE="$MY_DOCKER_FILE" \
--build-arg MY_IMAGE_NAME="$MY_IMAGE_NAME" \
--build-arg BUILD_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--build-arg BUILD_DATE=$(date +"%Y%m%d") \
--build-arg BUILD_TAG=$_BUILD_TAG \
--build-arg CI_PROJECT_URL=$_CI_PROJECT_URL \
--build-arg VCS_REF=$_VCS_REF \
--build-arg VCS_URL=$_VCS_URL \
--tag=$MY_BUILT_IMAGE --file=$MY_DOCKER_FILE $MY_DOCKER_CONTEXT
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment