Commit 1560c60c authored by Marcel Huber's avatar Marcel Huber
Browse files

Merge branch 'add-gitlab-ci-build' into 'master'

added gitlab-ci build file

See merge request !1
parents 8c2d62c0 994e1456
Pipeline #46 passed with stages
in 2 minutes and 39 seconds
.git
README.md
*.swp
*.tar
variables:
MY_IMAGE_NAME: "ArchLinux yaourt build image"
MY_BUILT_IMAGE: "archyaourt:latest"
MY_DOCKER_IMAGE: marcelhuberfoo/arch-yaourt
MY_DOCKER_FILE: Dockerfile
MY_DOCKER_CONTEXT: .
stages:
- build
- test
- deploy
before_script:
build:
image: docker:latest
stage: build
tags:
- docker
script:
- apk --no-cache --quiet add git
- env | sort
- ./build.sh
test:
stage: test
tags:
- docker
script:
- docker run --rm $MY_BUILT_IMAGE yaourt --version
deploy:
stage: deploy
tags:
- docker
only:
- tags
- triggers
script:
- 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
- docker rmi ${MY_BUILT_IMAGE}
FROM marcelhuberfoo/arch
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_DATE \
org.label-schema.schema-version="1.0"
ENV BUILD_DATE=$BUILD_DATE
ENV BUILD_TAG=$BUILD_TAG
USER root
RUN pacman -Syy -q --noconfirm git base-devel && \
printf "y\\ny\\n" | pacman -Scc
USER $UNAME
RUN cd /tmp && \
git clone https://aur.archlinux.org/package-query.git && \
( cd package-query && \
PKGEXT=.pkg.tar makepkg --syncdeps --install --noconfirm ) && \
git clone https://aur.archlinux.org/yaourt.git && \
( cd yaourt && \
PKGEXT=.pkg.tar makepkg --syncdeps --install --noconfirm ) && \
rm -rf /tmp/* && \
printf "y\\ny\\n" | sudo pacman -Scc
USER root
#!/bin/sh
_BUILD_TAG="$(git describe --abbrev=0 --tags 2>/dev/null)"
_VCS_URL="$(echo $CI_BUILD_REPO | 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_BUILD_REF_NAME:-master}).g$(git log -1 --format=%h)"
fi
set -e
docker build \
--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