Commit d01600bb authored by Peter Serwylo's avatar Peter Serwylo

Merge branch 'setup-deploy-script' into 'master'

Setup deploy script See merge request !62
parents 3941b52d 4c90a935
Pipeline #8222932 passed with stage
in 3 minutes 47 seconds
......@@ -9,38 +9,65 @@ variables:
STAGING_URL: $CI_COMMIT_REF_NAME-$CI_PROJECT_NAME-$CI_PROJECT_NAMESPACE.surge.sh
build:
stage: test
# Common steps required for each type of "Build" (f-droid.org, GitLab Pages, feature branches)
.setup_for_jekyll: &setup_for_jekyll |
ruby -v
apt-get update
apt-get install -y locales
echo "en_US UTF-8" > /etc/locale.gen
locale-gen en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_ALL=en_US.UTF-8
apt-get install -y zlib1g-dev
gem install jekyll bundler
bundle install --path vendor
#
# This is a manual task for building in preperation to deploy to
# https://f-droid.org. The intention is for it to be run locally using
# `gitlab-runner` each time a tag is found that is signed by a key in
# the whitelist keyring. Invoke like so:
#
# gitlab-runner exec docker f-droid.org --pre-build-script ./prepare-for-deploy.py \
# --docker-volumes "/root/deploy-whitelist-keyring.gpg:/root/.gnupg/pubring.gpg:ro" \
# --docker-volumes `pwd`/_site:/builds/output --env DEPLOY_DIR=/builds/output
#
# And when it is finished, you should have a directory in _site/build/
# which includes the entire static site ready to be deployed to
# https://f-droid.org.
#
f-droid.org:
stage: deploy
when: manual
cache:
paths: [ vendor/ruby ]
except:
- master
script:
- '[ ! -d "$DEPLOY_DIR" ] && echo "DEPLOY_DIR env variable must point to a directory" && exit 1'
- *setup_for_jekyll
- 'echo "url: https://f-droid.org" > userconfig.yml'
- 'echo "baseurl: \"\"" >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d $OUT_DIR --config _config.yml,userconfig.yml --verbose --trace
- cp -r $OUT_DIR $DEPLOY_DIR/
build:
stage: test
except: [ master ]
cache:
paths:
- vendor/ruby
paths: [ vendor/ruby ]
artifacts:
paths: [ $OUT_DIR ]
script:
- ruby -v
- apt-get update
- apt-get install -y locales
- echo "en_US UTF-8" > /etc/locale.gen
- locale-gen en_US.UTF-8
- export LANG=en_US.UTF-8
- export LANGUAGE=en_US:en
- export LC_ALL=en_US.UTF-8
- apt-get install -y zlib1g-dev
- gem install jekyll bundler
- bundle install --path vendor
- *setup_for_jekyll
- 'echo "url: https://$STAGING_URL" > userconfig.yml'
- 'echo baseurl: /$CI_PROJECT_NAME >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d $OUT_DIR/$CI_PROJECT_NAME --config _config.yml,userconfig.yml --verbose --trace
artifacts:
paths:
- $OUT_DIR
# This deploys feature branches to https://surge.sh, a free static site hosting service.
# See CONTRIBUTING.md for details of how to configure your GitLab project to enable this.
......@@ -48,18 +75,14 @@ build:
# branches alongside master branches (https://gitlab.com/gitlab-org/gitlab-pages/issues/33)
# this is the next best option.
preview:
stage: deploy
except:
- master
image: node:wheezy
except: [ master ]
# This is allowed to fail because only those who have setup $SURGE_LOGIN and $SURGE_TOKEN
# as GitLab secret variables (see CONTRIBUTING.md) are able to preview like this.
allow_failure: true
image: node:wheezy
script:
- npm install -g surge
- surge --project $OUT_DIR --domain $STAGING_URL
......@@ -72,23 +95,17 @@ preview:
teardown_preview:
stage: deploy
except:
- master
image: node:wheezy
except: [ master ]
when: manual
variables:
GIT_STRATEGY: none
when: manual
# This is allowed to fail because only those who have setup $SURGE_LOGIN and $SURGE_TOKEN
# as GitLab secret variables (see CONTRIBUTING.md) are able to preview like this.
allow_failure: true
image: node:wheezy
script:
- npm install -g surge
- surge teardown $STAGING_URL
......@@ -99,37 +116,20 @@ teardown_preview:
pages:
stage: deploy
only:
- master
only: [ master ]
cache:
paths:
- vendor/ruby
paths: [ vendor/ruby ]
artifacts:
paths: [ public ]
script:
- ruby -v
- apt-get update
- apt-get install -y locales
- echo "en_US UTF-8" > /etc/locale.gen
- locale-gen en_US.UTF-8
- export LANG=en_US.UTF-8
- export LANGUAGE=en_US:en
- export LC_ALL=en_US.UTF-8
- apt-get install -y zlib1g-dev
- gem install jekyll bundler
- bundle install --path vendor
- *setup_for_jekyll
# This is where GitLab pages will deploy to by default (e.g. "https://fdroid.gitlab.io/fdroid-website")
# so we need to make sure that the Jekyll configuration understands this.
- 'echo url: https://$CI_PROJECT_NAMESPACE.gitlab.io > userconfig.yml'
- 'echo baseurl: /$CI_PROJECT_NAME >> userconfig.yml'
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- echo "Additional Jekyll config used for CI:" && cat userconfig.yml
- bundle exec jekyll build -d public --config _config.yml,userconfig.yml
artifacts:
paths:
- public
#!/usr/bin/env python
# This script sets up this git repo for the final deploy process to
# https://f-droid.org. It will automatically delete changes in this
# local git repo that are not present in the git tag that is to be
# deployed. It is meant to be automatically triggered whenever the
# new index.jar has been published on f-droid.org.
#
# This script assumes two things:
# 1. the deploy machine includes the public GPG keys for tag verification
# 2. the 'origin' remote is set to https://gitlab.com/fdroid/fdroid-website
import os
import subprocess
import sys
remote_url = 'https://gitlab.com/fdroid/fdroid-website'
try:
import git
repo = git.Repo('.')
remote = None
for r in repo.remotes:
if r.url.startswith(remote_url):
remote = r.name
if not remote:
print('ERROR: git remote for ' + remote_url + ' is not setup!')
sys.exit(1)
subprocess.check_call(['git', 'remote', 'update', remote, '--prune'])
subprocess.check_call(['git', 'fetch', remote, '--tags'])
except ImportError:
subprocess.check_call(['git', 'remote', 'update', '--prune'])
subprocess.check_call(['git', 'fetch', '--tags'])
FNULL = open(os.devnull, 'w')
tags = subprocess.check_output(['git', 'tag'])
current_date = 0
current_tag = None
for tag in tags.split('\n'):
if not tag:
continue
result = subprocess.call(['git', 'tag', '-v', tag], stdout=FNULL, stderr=FNULL)
if result != 0:
continue
try:
date = int(subprocess.check_output(['git', 'log', '--format=format:%at', '-1', tag]))
if date > current_date:
current_date = date
current_tag = tag
except ValueError:
continue
if current_tag:
subprocess.call(['git', 'tag', '-v', current_tag]) # call again just to get output
subprocess.check_call(['git', 'clean', '-fdx'])
subprocess.check_call(['git', 'reset', '--hard', current_tag])
print('Set up ' + current_tag + ' to deploy!')
else:
print('ERROR: could not find any signed release tags!')
sys.exit(1)
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