Commit 253ac4ad authored by morph027's avatar morph027

Stretch

parent 4daaf5a4
variables:
DOCKER_TAG: "1"
SOGO_MAJOR_VERSION: "3"
USER: "gitlab-ci"
REGISTRY: $CI_REGISTRY
IMAGE: $CI_PROJECT_NAME
NAMESPACE: $CI_PROJECT_NAMESPACE
DOCKER_TAG: "stretch"
stages:
- build_docker
- build_sogo
- upload_packages
- docker
- sogo
- upload
- pages
build_docker:
stage: build_docker
docker:
stage: docker
image: docker:git
services:
- docker:dind
script:
- alias 'dockerize=git whatchanged HEAD^! | grep Dockerfile >/dev/null'
- dockerize && docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $REGISTRY
- dockerize && apk --no-cache add bash
- dockerize && ${CI_PROJECT_DIR}/.gitlab-ci/dockerize.sh
- dockerize || (echo "no need to build new docker image" && exit 0)
- docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN $CI_REGISTRY
- docker build -t $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$DOCKER_TAG .
- docker push $CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME:$DOCKER_TAG
only:
changes:
- Dockerfile
refs:
- tags
build_sogo:
stage: build_sogo
image: ${REGISTRY}/${NAMESPACE}/${IMAGE}:${DOCKER_TAG}
build:
stage: sogo
image: ${CI_REGISTRY}/${CI_PROJECT_NAMESPACE}/${CI_PROJECT_NAME}:${DOCKER_TAG}
script:
- alias 'dockerize=git whatchanged HEAD^! | grep Dockerfile >/dev/null'
- dockerize && sleep 10
- export VAR=( LOCAL_SOGO_REPO )
- . <(curl -sL https://gitlab.com/morph027/gitlab-ci-helpers/raw/master/check-vars.sh)
- $CI_PROJECT_DIR/.gitlab-ci/build.sh
artifacts:
paths:
- $CI_PROJECT_DIR/*.deb
only:
- tags
upload_packages:
stage: upload_packages
image: docker:git
upload:
stage: upload
image: ruby:alpine
script:
- apk --no-cache add bash ruby-dev build-base gnupg
- gem install deb-s3
- .gitlab-ci/upload.sh
only:
- tags
pages:
variables:
HUGO: "0.51"
stage: pages
image: ubuntu:bionic
script:
- apk --no-cache add bash curl
- $CI_PROJECT_DIR/.gitlab-ci/upload.sh
- apt-get update
- apt-get install -y apt-mirror apt-transport-https curl git-core python3-pip
- pip3 install pydpkg
- curl -sLO https://github.com/gohugoio/hugo/releases/download/v${HUGO}/hugo_${HUGO}_Linux-64bit.deb
- dpkg -i hugo_${HUGO}_Linux-64bit.deb
- cp $CI_PROJECT_DIR/mirror.list /etc/apt/mirror.list
- apt-mirror
- git clone https://github.com/vjeantet/hugo-theme-docdock themes/docdock
- cat README.md >> content/_index.md
- sed -i 's,^date.*,date = "'$(date +%Y-%m-%dT%H:%M:%S%:z)'",' content/_index.md
- mv /var/spool/apt-mirror/mirror/repo.morph027.de/mirror $CI_PROJECT_DIR/public
- python3 docdock.py public https://$CI_PROJECT_NAMESPACE.gitlab.io/$CI_PROJECT_NAME
- hugo
- curl -L -o $CI_PROJECT_DIR/public/gpg.key https://repo.morph027.de/gpg.key
artifacts:
paths:
- $CI_PROJECT_DIR/public
expire_in: 1 day
only:
- tags
#!/bin/bash
## set some vars
# preprends the version tags we want to fetch, e.g. SOGo-3.1.5. Github API additionally prepends "refs/tags"
# defaults to "refs/tags/SOGo-" and can be set via REPO_TAG_PREFIX variable
TAG_PREFIX="${REPO_TAG_PREFIX:-refs/tags/SOGo-}"
## fetch package index from the personal repo and get current SOGo version
LOCAL_SOGO_VERSION=$(curl -s ${LOCAL_SOGO_REPO} | zcat | awk '/^Package: sogo$/,/^Version:/' | grep "Version" | head -n1 | grep -oE '([0-9])(\.[0-9])+')
## fetch tags from SOGo Github repo using API and get latest tag matching $TAG_PREFIX
REPO_SOGO_VERSION=$(curl -s https://api.github.com/repos/inverse-inc/sogo/git/refs/tags?sort=created | jq -r '.[] | select( .ref | contains("'${TAG_PREFIX}${SOGO_MAJOR_VERSION}'") ) | .ref' | tail -n1 | sed 's,^'$TAG_PREFIX',,')
## bail on error (not before this line, casue LOCAL_SOGO_VERSION might throw error code 1 on non-existing package index, which creates a build)
set -e
## check for valid Github tag
if [[ ! $REPO_SOGO_VERSION =~ ^[0-9].*$ ]]; then
echo "unable to fetch new version tag"
fi
## print values
echo "Locally available: $LOCAL_SOGO_VERSION"
echo "Available in repository: $REPO_SOGO_VERSION"
## if values do not match, build SOGo packages
if [[ ! $LOCAL_SOGO_VERSION =~ ^${REPO_SOGO_VERSION}$ ]]; then
# build instructions: http://wiki.sogo.nu/Packaging
git clone -b SOPE-$REPO_SOGO_VERSION https://github.com/inverse-inc/sope
git clone -b SOGo-$REPO_SOGO_VERSION https://github.com/inverse-inc/sogo
cd sope
cp -a packaging/debian debian
./debian/rules
dpkg-buildpackage
cd $CI_PROJECT_DIR
dpkg -i *deb
cd sogo
cp -a packaging/debian debian
sed -i 's,^sogo (1.3.5),sogo ('$REPO_SOGO_VERSION'),' debian/changelog
cp packaging/debian-multiarch/control-no-openchange debian
./debian/rules
dpkg-buildpackage -b
else
echo "no new version found, cancelling build ..."
BASE_URL=$(echo $CI_PROJECT_URL | cut -d'/' -f1-3)
curl -s -X POST -H "PRIVATE-TOKEN: ${PRIVATE_TOKEN}" "${BASE_URL}/api/v3/projects/${CI_PROJECT_ID}/builds/${CI_BUILD_ID}/cancel" | python -m json.tool
fi
# build instructions: http://wiki.sogo.nu/Packaging
git clone -b SOPE-${CI_COMMIT_TAG%%-*} https://github.com/inverse-inc/sope
git clone -b SOGo-${CI_COMMIT_TAG%%-*} https://github.com/inverse-inc/sogo
cd sope
cp -a packaging/debian debian
./debian/rules
dpkg-buildpackage
cd $CI_PROJECT_DIR
dpkg -i *deb
cd sogo
cp -a packaging/debian debian
sed -i 's,^sogo (1.3.5),sogo ('${CI_COMMIT_TAG%%-*}'),' debian/changelog
cp packaging/debian-multiarch/control-no-openchange debian
./debian/rules
dpkg-buildpackage -b
#!/bin/bash
. <(curl -fksSL https://gitlab.com/morph027/gitlab-ci-helpers/raw/master/docker-build.sh)
docker_build
docker_tag
docker_push
#!/bin/bash
#!/bin/sh
if [ ! -z $APTLY_CLI_URL ]; then
echo "$SIGNING_KEY" > /tmp/key
gpg --import /tmp/key
VARS=( REPO_NAME REPO_DIST CI_PROJECT_ID )
. <(curl -fsSL https://gitlab.com/morph027/gitlab-ci-helpers/raw/master/check-vars.sh)
curl -fsSL -X POST \
-F token=$APTLY_CLI_PRIVATE_TOKEN \
-F ref=master \
-F "variables[REPO_NAME]=$REPO_NAME" \
-F "variables[REPO_DIST]=$REPO_DIST" \
-F "variables[PROJECT]=$CI_PROJECT_ID" \
-F "variables[STAGE]=build_sogo" \
-F "variables[REF]=$CI_BUILD_REF_NAME" \
$APTLY_CLI_URL
fi
find "${CI_PROJECT_DIR}" -type f -name '*.deb' -exec \
deb-s3 upload \
--bucket $BUCKET \
--endpoint $S3 \
--arch amd64 \
--codename $CODENAME \
--access-key-id=$ACCESS_KEY \
--secret-access-key=$SECRET_KEY \
--force-path-style \
--sign=$SIGNING_KEY_ID \
{} \+
## packages according to http://wiki.sogo.nu/Compilation
FROM debian:8
FROM debian:stretch
RUN apt-get update \
&& apt-get -y install \
......@@ -18,7 +18,8 @@ RUN apt-get update \
libssl-dev \
zlib1g-dev \
libpq-dev \
libmysqlclient-dev \
libmariadbclient-dev \
libmariadbclient-dev-compat \
libmemcached-dev \
python-m2crypto \
python-simplejson \
......@@ -37,7 +38,7 @@ RUN apt-get update \
&& apt-get clean
RUN cd /tmp/ \
&& curl -O https://packages.inverse.ca/SOGo/nightly/2/debian/pool/jessie/w/wbxml2/libwbxml2-dev_0.11.2-1.1_amd64.deb \
&& curl -O https://packages.inverse.ca/SOGo/nightly/2/debian/pool/jessie/w/wbxml2/libwbxml2-0_0.11.2-1.1_amd64.deb \
&& curl -O https://packages.inverse.ca/SOGo/nightly/4/debian/pool/stretch/w/wbxml2/libwbxml2-dev_0.11.6-1_amd64.deb \
&& curl -O https://packages.inverse.ca/SOGo/nightly/4/debian/pool/stretch/w/wbxml2/libwbxml2-0_0.11.6-1_amd64.deb \
&& dpkg -i libwbxml2-*deb \
&& rm -f libwbxml2-*deb
# [SOGo](https://sogo.nu/) Packages
This project basically just builds SOGo packages according to the [instructions](http://wiki.sogo.nu/Compilation). Afterwards, packages are being pushed to [my repo](https://repo.morph027.de).
This project basically just builds SOGo packages according to the [instructions](http://wiki.sogo.nu/Compilation).
If you want to use this for yor personal repo, just fork this project (or import into your on-premise Gitlab) and adjust the private project variable ```LOCAL_SOGO_REPO``` to the ```Packages.gz``` file of your repository which contains SOGo packages (e.g. ```https://repo.morph027.de/sogo/dists/jessie/main/binary-amd64/Packages.gz```).
### Add repo signing key to apt
## Docker image
```bash
wget -q -O - https://packaging.gitlab.io/sogo/gpg.key | sudo apt-key add -
```
This project also includes the neccessary docker image to build SOGo. It will be built before packages if there are changes to the Dockerfile. Do not forget to update the ```$DOCKER_TAG``` variable in ```.gitlab-ci.yml```!
To setup the process and images, you'll need to set the following project variables:
or
* ```REGISTRY```: the registry to push and pull, most likely ```registry.gitlab.com```
* ```NAMESPACE```: the namespace of this project (e.g. ```packaging```)
* ```IMAGE_NAME```: equals project name (e.g. ```sogo```)
```bash
curl -sL https://packaging.gitlab.io/sogo/gpg.key | sudo apt-key add -
```
You now can trigger builds via `Run pipeline` button or using the API.
### Add repo to apt
## Package upload (optional)
You can use a fork of [gitlab-ci-aptly-cli](https://gitlab.com/morph027/gitlab-ci-aptly-cli) to upload packages to your repo. Just make sure, you've set all mandatory project variables in the sogo project.
This project is using these variables (to not distract the code):
* ```REPO_DIST```: name of the distribution to publish in aptly
* ```REPO_NAME```: name of the repository defined in your aptly setup
* ```APTLY_CLI_PRIVATE_TOKEN```: the token for the trigger below
* ```APTLY_CLI_URL```: the URL which actually triggers the aptly ci job (e.g. ```https://gitlab.com/api/v3/projects/XXXXXX/trigger/builds```)
* ```LOCAL_SOGO_REPO```: see introduction
```bash
echo "deb [arch=amd64] https://packaging.gitlab.io/sogo/sogo stretch main" | sudo tee /etc/apt/sources.list.d/morph027-sogo-stretch.list
```
baseURL = "https://packaging.gitlab.io/sogo"
languageCode = "en-us"
title = "morph027 sogo repo"
theme = "docdock"
[outputs]
home = [ "HTML", "RSS", "JSON"]
[[menu.shortcuts]]
pre = "<h3>More</h3>"
name = "<i class='fa fa-gitlab'></i> <label>Repo</label>"
identifier = "ds"
url = "https://gitlab.com/packaging/sogo/"
weight = 10
+++
draft = false
title = "Footer"
description = "Footer"
date = "2017-04-24T18:36:24+02:00"
+++
**Disclaimer: Use at your own risk!**
+++
draft = false
title = "Home"
description = "Repo"
date = "2017-04-24T18:36:24+02:00"
+++
#!/usr/bin/env python3
import sys
import os
import os.path
from pydpkg import Dpkg
from urllib.parse import urlparse
def get_deb_packages(path):
packages = []
for dirpath, dirnames, filenames in os.walk(path):
for filename in [f for f in filenames if f.endswith('.deb')]:
packages.append(os.path.join(dirpath, filename))
return packages
def get_distros(repo):
distros = []
for distro in os.listdir(repo):
if os.path.isdir(repo + '/' + distro):
distros.append(distro)
return distros
def get_repos(path):
repos = []
for repo in os.listdir(path):
if os.path.isdir(path + '/' + repo):
repos.append(repo)
return repos
def main(path, baseurl):
if not os.path.exists('content'):
os.makedirs('content')
repos = get_repos(path)
for repo in repos:
if not os.path.exists('content/' + repo):
os.makedirs('content/' + repo)
repo_index = open('content/' + repo + '/_index.md','w')
repo_index.write('+++\n')
repo_index.write('title = "' + repo.capitalize() + '"\n')
repo_index.write('+++\n')
repo_index.write('## Available distributions\n')
repo_index.write('\n')
distros = get_distros(path +'/' + repo + '/dists')
for distro in distros:
repo_index.write('* ' + distro.capitalize() + '\n')
if not os.path.exists('content/' + repo + '/' + distro):
os.makedirs('content/' + repo + '/' + distro)
distro_index = open('content/' + repo + '/' + distro + '/_index.md','w')
distro_index.write('+++\n')
distro_index.write('title = "' + distro.capitalize() + '"\n')
distro_index.write('+++\n')
distro_index.write('```bash\n')
distro_index.write('echo "deb [arch=amd64] ' + baseurl + '/' + repo + ' ' + distro + ' main" | sudo tee /etc/apt/sources.list.d/' + urlparse(baseurl).netloc + '-' + repo + '-' + distro + '.list\n')
distro_index.write('```\n\n')
distro_index.write('## Available packages\n')
packages = get_deb_packages(path +'/' + repo + '/pool/' + distro)
for package in packages:
dp = Dpkg(package)
distro_index.write('* ' + dp.package + '\n')
if not os.path.exists('content/' + repo + '/' + distro + '/' + dp.package):
os.makedirs('content/' + repo + '/' + distro + '/' + dp.package)
package_index = open('content/' + repo + '/' + distro + '/' + dp.package + '/_index.md','w')
package_index.write('+++\n')
package_index.write('title = "' + dp.package + '"\n')
package_index.write('+++\n')
package_index.write('{{< button align="center" theme="info" href="' + baseurl + package.split(path)[1] + '" >}} Download {{< /button >}}\n')
package_index.write('```\n')
package_index.write(str(dp) + '\n')
package_index.write('```\n')
package_index.close()
distro_index.close()
repo_index.close()
if __name__ == "__main__":
main(sys.argv[1], sys.argv[2])
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# set mirror_path $base_path/mirror
# set skel_path $base_path/skel
# set var_path $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ##############
deb [arch=amd64] https://repo.morph027.de/mirror/sogo stretch main
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