Skip to content

Commit

Permalink
Merged release/0.9 into master
Browse files Browse the repository at this point in the history
  • Loading branch information
aacebedo committed Feb 14, 2016
2 parents d190a6e + 88f5213 commit 05cd254
Show file tree
Hide file tree
Showing 110 changed files with 289 additions and 31,745 deletions.
53 changes: 53 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
sudo: required

language: go
go:
- 1.5

services:
- docker

before_install:
- sudo apt-get update
- sudo apt-get install -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" -y --force-yes -q docker-engine
- docker build -t aacebedo/cfdnsupdaterbuild environments/build
- sudo mkdir -m 777 -p /build/vivid/amd64 /build/vivid/arm
- sudo mkdir -m 777 -p /build/wily/amd64 /build/wily/arm
- sudo mkdir -m 777 -p /build/xenial/amd64 /build/xenial/arm

script:
- docker run -t -v /build/vivid/amd64:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a amd64 -o /build
- docker run -t -v /build/vivid/arm:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a arm -o /build
- docker run -t -v /build/wily/amd64:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a amd64 -o /build
- docker run -t -v /build/wily/arm:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a arm -o /build
- docker run -t -v /build/xenial/amd64:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a amd64 -o /build
- docker run -t -v /build/xenial/arm:/build aacebedo/cfdnsupdaterbuild build -p aacebedo/cfdnsupdater -bn cfdnsupdater -b $TRAVIS_BRANCH -a arm -o /build
- docker run -t -v /build:/build aacebedo/cfdnsupdaterbuild deploydesc -bn cfdnsupdater -b $TRAVIS_BRANCH -dc "Cloudflare DNS updater" -u aacebedo -li LGPL-3.0 -o /build

after_success:
- sudo chmod -R a+rwX /build
- mv /build/xenial/amd64/cfdnsupdater.tar /build/cfdnsupdater.amd64.$TRAVIS_BRANCH.tar
- mv /build/xenial/arm/cfdnsupdater.tar /build/cfdnsupdater.arm.$TRAVIS_BRANCH.tar

deploy:
- provider: bintray
skip_cleanup: true
file: /build/bintray.desc
user: $BINTRAY_USERNAME
key: $BINTRAY_APIKEY
dry-run: false
on:
tags: true
- provider: releases
skip_cleanup: true
api-key:
secure: $GITHUB_TOKEN
file:
- /build/cfdnsupdater.amd64.$TRAVIS_BRANCH.tar
- /build/cfdnsupdater.arm.$TRAVIS_BRANCH.tar
on:
tags: true
- provider: script
script: docker login -u $BINTRAY_USERNAME -p $BINTRAY_APIKEY -e $BINTRAY_EMAIL aacebedo-docker-cfdsnupdater.bintray.io && docker build --build-arg VERSION=$TRAVIS_BRANCH -f environments/run/Dockerfile.amd64 -t aacebedo/cfdnsupdater-amd64 . && docker tag aacebedo/cfdnsupdater-amd64 aacebedo-docker-cfdsnupdater.bintray.io/cfdnsupdater-amd64:$TRAVIS_BRANCH && docker push aacebedo-docker-cfdsnupdater.bintray.io/cfdnsupdater-amd64:$TRAVIS_BRANCH
on:
tags: true
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,44 @@ It can be built like any other Go apps. However I provide a Dockerfile
to ease the process. Execute the following commands.
```sh
$ docker build -t cfdnsupdaterbuild ./environments/build
$ docker run -t -v <output_path_on_host>:/out cfdnsupdaterbuild -a <ARCH> [-b <BRANCH or TAG>]
$ docker run -t -v <output_path_on_host>:/build cfdnsupdaterbuild -a <ARCH> \
[-b <BRANCH or TAG>] -p aacebedo/cfdnsupdater -bn cfdnsupdater -o /build
```

This command will create a tar gz and debian file in the build directory
of the container.

### Installation
There are multiple ways to install the software. Package for ARM and amd64
available for each methods.

#### Archive
Get an archive on github and execute the following commands.
```sh
$ tar xvzf ./cfdnsupdater.<ARCH>.<VERSION>.tar.gz
```
Note: I also provide a systemd file you can manually install in the
appropriate directory ("/etc/systemd/system" for instance).

#### Debian repository
Add the following debian repository to your apt source and install it through
apt-get
```sh
$ "deb https://dl.bintray.com/aacebedo/cfdnsupdater <DISTRIBUTION> main" | \
sudo tee -a /etc/apt/sources.list
$ sudo apt update
$ sudo apt install cfdnsupdater
```

#### Docker registry
Pull the docker image and run it in a container
```sh
docker pull aacebedo-docker-cfdsnupdater.bintray.io/cfdnsupdater-amd64:<VERSION>
```

### Use

```sh
$ cfdnsupdater fileconfig -c <path_to_configuration_file>
$ cfdnsupdater -c <path_to_configuration_file>
```
Here is an example of a configuration file (also included in the distribution):
```sh
Expand Down
20 changes: 11 additions & 9 deletions environments/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@
# along with CFDNSUpdater. If not, see <http://www.gnu.org/licenses/>.

from alpine
RUN apk add --update go git python3 bash

ENV GOPATH /go
ENV CGO_ENABLED=0

ADD ./build.py /usr/bin
RUN apk update
RUN apk upgrade
RUN apk add go git python3 bash ruby-dev gcc make ruby ruby-bundler \
g++ libstdc++ libffi-dev ruby-rdoc tar
RUN apk add ruby-irb ruby-rdoc
RUN gem install fpm

COPY ./build.py /usr/bin/
RUN chmod u+x /usr/bin/build.py

WORKDIR /out
VOLUME ["/out"]
WORKDIR /build
VOLUME ["/build"]

ENTRYPOINT ["build.py", "-p", "aacebedo/cfdnsupdater", "-n", "cfdnsupdater"]
ENTRYPOINT ["build.py"]



222 changes: 180 additions & 42 deletions environments/build/build.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,75 +1,213 @@
#!/usr/bin/env python3
#This file is part of CFDNSUpdater.
# This file is part of CFDNSUpdater.
#
# CFDNSUpdater is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CFDNSUpdater is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# but WITHbuild ANY WARRANTY; withbuild even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with CFDNSUpdater. If not, see <http://www.gnu.org/licenses/>.

import json
import argparse
import subprocess
import sys
import os
import tarfile
import uuid
import time
import shutil
from subprocess import Popen, PIPE
from errno import ENAMETOOLONG

def parseArguments(raw_args):
parser = argparse.ArgumentParser(prog="build",
description='Project Builder')
parser.add_argument('-project','-p',required=True,help="Github project", type=str)
parser.add_argument('-binname','-n',required=True,help="Binary name project", type=str)

parser.add_argument('-arch','-a',required=True, help='Architecture to build', type=str)

parser.add_argument('--branch', '-b', help='Git branch to build', default="master", type=str)
rootSubparsers = parser.add_subparsers(dest="function")
buildParser = rootSubparsers.add_parser('build', help='Build packages')
buildParser.add_argument('-project', '-p', required=True,
help="Github project", type=str)
buildParser.add_argument('-arch', '-a', required=True,
help='Architecture to build', type=str)
buildParser.add_argument('--branch', '-b', help='Git branch to build',
default="master", type=str)
buildParser.add_argument('-binname', '-bn', required=True,
help='binname', type=str)
buildParser.add_argument('--outputdirpath', '-o', help='Output directory',
required=True, type=str)

deployDescParser = rootSubparsers.add_parser('deploydesc',
help='Create deployement \
descriptor')
deployDescParser.add_argument('--branch', '-b', help='Git branch to build',
required=True, type=str)
deployDescParser.add_argument('-binname', '-bn', required=True,
help='binname', type=str)
deployDescParser.add_argument('-user', '-u', required=True,
help='User', type=str)
deployDescParser.add_argument('-description', '-dc', required=True,
help='Package description', type=str)
deployDescParser.add_argument('--outputdirpath', '-o',
help='Output directory',
required=True, type=str)
deployDescParser.add_argument('--licenses', '-li', help='Software licences',
default=[], type=str, action='append')
deployDescParser.add_argument('--labels', '-la', help='Package labels',
action='append',
default=[], type=str)
return parser.parse_args(raw_args)


def build(project, branch, arch, bin_name):
if not os.path.exists(os.path.join("/", "out", "project")) :
os.makedirs(os.path.join("/", "out","project"), exist_ok=True)
process = None
process = subprocess.Popen(["git", "clone", "-b", branch,
"https://github.com/{}".format(project),
os.path.join("/","out","project")],
shell=False, stdout=PIPE)
stdout,err = process.communicate()
if err != None:
os.exit("Error while cloning project: {}".format(err))
def generateTmpDir():
tmp_dir_path = None
for x in range(0, 5):
tmp_dir_path = os.path.join(os.path.abspath(os.sep), "tmp", str(uuid.uuid4()))
if not os.path.exists(tmp_dir_path) :
os.makedirs(tmp_dir_path, exist_ok=True)
break
else:
tmp_dir_path = None
if tmp_dir_path == None:
raise Exception("Unable to generate a tmp direcctory")
return tmp_dir_path

def generatePackage(build_dir_path,
package_type, package_name, version, arch):
process = subprocess.Popen(["fpm", "-t", package_type,
"-n", package_name,
"-p", build_dir_path,
"-a", arch,
"-f",
"-v", version.replace("/", "_"),
"-C", os.path.join(build_dir_path, "packaging"),
"-s", "dir", "."], shell=False)
process.communicate()
if process.returncode != 0:
os.exit("Error while cloning project")

else:
print("Project already exists, branch name is ignored")
def build(build_dir_path, project, branch, arch, bin_name):
if len(os.listdir(build_dir_path)) != 0:
raise Exception("Build error: {} is not empty.".format(build_dir_path))
go_dir_path = os.path.join(generateTmpDir(), "go")
print("Go path is : {}".format(go_dir_path))
src_dir_path = os.path.join(go_dir_path, 'src', "github.com", project)

go_path = "{}:/out/project".format(os.environ["GOPATH"])
process = None
process = subprocess.Popen(["git", "clone", "-b", branch,
"https://github.com/{}".format(project),
src_dir_path], shell=False)
process.communicate()
if process.returncode != 0:
os.exit("Error while cloning project")

process = subprocess.Popen(["go", "get", "-d", "./..."],
cwd=os.path.join("/", "out", "project"), shell=False,
env=dict(os.environ, GOARCH=arch, GOPATH=go_path), stdout=PIPE)
stdout,err = process.communicate()
if err != None:
os.exit("Error while getting dependencies: {}".format(err))

process = subprocess.Popen(["go", "build", '-o', os.path.join('bin', bin_name), bin_name],
cwd=os.path.join("/", "out", "project"), shell=False,
env=dict(os.environ, GOARCH=arch, GOPATH=go_path), stdout=PIPE)
stdout,err = process.communicate()
if err != None:
os.exit("Error while building project: {}".format(err))

with tarfile.open(os.path.join("/", "out","project", "{}.{}.{}.tar.gz".format(bin_name, arch, branch)), "w:gz") as tar:
tar.add(os.path.join("/", "out", "project", "bin", bin_name), arcname=bin_name)
cwd=src_dir_path, shell=False,
env=dict(os.environ,
GOARCH=arch,
GOPATH=go_dir_path,
CGO_ENABLED="0"))
process.communicate()
if process.returncode != 0:
sys.exit("Error while getting dependencies project")

process = subprocess.Popen(["go", "install", "./..."],
cwd=src_dir_path, shell=False,
env=dict(os.environ,
GOARCH=arch,
GOPATH=go_dir_path,
CGO_ENABLED="0"))
process.communicate()
if process.returncode != 0:
os.exit("Error while build the project")
bin_dir_path = os.path.join(build_dir_path, "packaging",
"usr", "local", "bin")
os.makedirs(bin_dir_path)
for dirName, _, fileList in os.walk(os.path.join(go_dir_path, "bin")):
for fname in fileList:
shutil.copy2(os.path.join(dirName, fname),
os.path.join(bin_dir_path, fname))

if __name__ == "__main__":
parsed_args = parseArguments(sys.argv[1:])
build(parsed_args.project,parsed_args.branch,parsed_args.arch,parsed_args.binname)
if os.path.exists(os.path.join(src_dir_path, "resources")) :
for name in os.listdir(os.path.join(src_dir_path, "resources")):
shutil.copytree(os.path.join(src_dir_path, "resources", name),
os.path.join(build_dir_path, "packaging", name))

def generateBintrayDescriptor(build_dir,
bin_name,
user,
desc,
version,
licenses=[],
labels=[]):
github_addr = "https://github.com/{}/{}".format(user,bin_name)
descriptor = {"package":{
"name":bin_name,
"repo":bin_name,
"subject":user,
"desc":desc,
"website_url":github_addr,
"issue_tracker_url":github_addr,
"vcs_url":github_addr,
"github_use_tag_release_notes":True,
"licenses":licenses,
"labels":labels,
"public_download_numebrs":False,
"public_stats":False
},
"version":{
"name":version,
"desc":desc,
"released":time.strftime("%Y-%m-%d"),
"vcs_tag":version,
"gpgSign":False
},
"files":[],
"publish":True
}

for distrib in os.listdir(build_dir):
if os.path.isdir(os.path.join(build_dir,distrib)):
for arch in os.listdir(os.path.join(build_dir,distrib)):
if os.path.isdir(os.path.join(build_dir,distrib,arch)) :
descriptor["files"].append({
"includePattern": os.path.join(build_dir,
distrib,
arch,
"(.*\.deb)"),
"uploadPattern": os.path.join(distrib,"$1"),
"matrixParams":
{
"deb_distribution":distrib,
"deb_component":"main",
"deb_architecture":arch
}
})
file = open(os.path.join(build_dir, "bintray.desc"), 'w')
json.dump(descriptor, file, ensure_ascii=False, indent=2)
file.close()

if __name__ == "__main__":
args = parseArguments(sys.argv[1:])

if not os.path.exists(args.outputdirpath):
os.makedirs(args.outputdirpath, exist_ok=True)
if args.function == "build" :
build(args.outputdirpath,
args.project, args.branch,
args.arch, args.binname)
generatePackage(args.outputdirpath, "deb", args.binname,
args.branch, args.arch)
generatePackage(args.outputdirpath, "tar", args.binname,
args.branch, args.arch)
else:
generateBintrayDescriptor(args.outputdirpath,
args.binname,
args.user,
args.description,
args.branch,
args.licenses,
args.labels)
Loading

0 comments on commit 05cd254

Please sign in to comment.