├── .gitignore ├── fedora-package ├── run.sh ├── scripts │ └── review-from-bugzilla.sh └── Dockerfile ├── centos-repo-builder ├── _rpmmacros ├── build ├── Dockerfile └── run ├── zanata-server ├── .env ├── conf │ ├── admin-user-setup.sql │ └── standalone.xml ├── rundb.sh ├── common ├── docker-compose.yml ├── Dockerfile ├── README.md └── runapp.sh ├── testDockerHelper.py ├── README.md ├── image-make └── DockerHelper.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ -------------------------------------------------------------------------------- /fedora-package/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo === building the image... 4 | docker build -t fedorareview . 5 | 6 | echo === finish building the image 7 | echo === running the container... 8 | docker run --name fedorareview --rm -it --cap-add=SYS_ADMIN fedorareview mock 9 | 10 | -------------------------------------------------------------------------------- /centos-repo-builder/_rpmmacros: -------------------------------------------------------------------------------- 1 | %home %(echo $HOME) 2 | %_smp_mflags -j3 3 | %__arch_install_post /usr/lib/rpm/check-rpaths /usr/lib/rpm/check-buildroot 4 | %_topdir @RPMBUILD_TOPDIR@ 5 | %_specdir @REPO_DIR@ 6 | %_sourcedir @RPMBUILD_SOURCEDIR@ 7 | %_rpmdir @REPO_DIR@/epel-@CENTOS_VERSION@ 8 | %_srcrpmdir @REPO_DIR@/epel-@CENTOS_VERSION@/SRPMS 9 | %dist .el@CENTOS_VERSION@ 10 | -------------------------------------------------------------------------------- /zanata-server/.env: -------------------------------------------------------------------------------- 1 | # General settings 2 | ZANATA_PORT=8080 3 | ZANATA_VERSION=latest 4 | # Set to 1 to enable daemon mode 5 | ZANATA_DAEMON_MODE=0 6 | 7 | # Database settings 8 | ZANATA_MYSQL_USER=zanata 9 | ZANATA_MYSQL_PASSWORD=password 10 | ZANATA_MYSQL_DATABASE=zanata 11 | 12 | # Mail settings 13 | ZANATA_MAIL_HOST=localhost 14 | ZANATA_MAIL_PORT=25 15 | ZANATA_MAIL_TLS=false 16 | ZANATA_MAIL_SSL=false 17 | ZANATA_MAIL_USERNAME=" " 18 | ZANATA_MAIL_PASSWORD=" " -------------------------------------------------------------------------------- /zanata-server/conf/admin-user-setup.sql: -------------------------------------------------------------------------------- 1 | -- Username: admin 2 | -- Password: admin1234 3 | INSERT INTO HAccount (id, creationDate, lastChanged, versionNum, enabled, passwordHash, username) 4 | VALUES (1, now(), now(), 1, 1, 'UZMf4PIqtTBGAo9wWKuTpg==', 'admin'); 5 | 6 | INSERT INTO HPerson (id, creationDate, lastChanged, versionNum, email, `name`, accountId) 7 | VALUES (1, now(), now(), 1, 'admin@noreply.org', 'Administrator', 1); 8 | 9 | INSERT INTO HAccountMembership(accountId, memberOf) VALUES (1, 5); 10 | -------------------------------------------------------------------------------- /fedora-package/scripts/review-from-bugzilla.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo bug number is given as: $1 4 | BUG=$1 5 | 6 | re='^[0-9]+$' 7 | if ! [[ $BUG =~ $re ]] ; then 8 | echo "error: give first argument as the Bugzilla number" >&2; exit 1 9 | fi 10 | 11 | cd ~ 12 | # remove any previous folder 13 | rm -rf "$BUG-*" 14 | 15 | # /usr/bin must be before /usr/sbin otherwise mock will throw error 16 | PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin 17 | 18 | fedora-review -b $BUG -m fedora-rawhide-x86_64 19 | 20 | -------------------------------------------------------------------------------- /fedora-package/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM fedora 2 | 3 | # there is an issue in either fedora-review or mock where you need to run dnf makecache first 4 | RUN dnf install -y fedora-review fedora-review-plugin-java sudo && dnf clean all && dnf makecache 5 | 6 | # the ordinary non-root user for running fedora-review 7 | ENV USER=reviewer 8 | # create a new non root user and add to group: wheel, mock 9 | RUN useradd -m -g mock -G wheel -d /home/$USER $USER && echo 'reviewer' | passwd --stdin $USER \ 10 | && sed -i -e "s|# %wheel|$USER|" /etc/sudoers 11 | 12 | # copy some utility scripts 13 | COPY scripts/ /home/$USER/scripts/ 14 | 15 | RUN chmod -R 755 /home/$USER/scripts/ 16 | 17 | USER $USER 18 | 19 | ENTRYPOINT ["newgrp"] 20 | 21 | -------------------------------------------------------------------------------- /zanata-server/rundb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | ### This program sets up the data volume and database containers for Zanata 3 | 4 | ScriptFile=$(realpath ${BASH_SOURCE[0]}) 5 | ScriptDir=$(dirname $ScriptFile) 6 | source $ScriptDir/common 7 | ensure_docker_network 8 | 9 | ## Create zanata-db volume if it is missing 10 | if ! (docker volume ls -q | grep zanata-db) ; then 11 | docker volume create --name zanata-db 12 | fi 13 | 14 | if [ -z $(docker ps -aq -f name=zanatadb) ];then 15 | ## Create new container if zanatadb does not exist 16 | docker run --name zanatadb \ 17 | -e MYSQL_USER=${ZANATA_MYSQL_USER} -e MYSQL_PASSWORD=${ZANATA_MYSQL_PASSWORD} \ 18 | -e MYSQL_DATABASE=${ZANATA_MYSQL_DATABASE} -e MYSQL_RANDOM_ROOT_PASSWORD=yes \ 19 | -v zanata-db:/var/lib/mysql:Z \ 20 | --net ${ZANATA_DOCKER_NETWORK} \ 21 | -d mariadb:10.1 \ 22 | --character-set-server=utf8 --collation-server=utf8_general_ci 23 | elif [ -n $(docker ps -aq -f name=zanatadb -f status=exited) ];then 24 | ## Start container if zanatadb stopped 25 | docker start zanatadb 26 | fi 27 | 28 | echo 'Please use the command "docker logs zanatadb" to check that MariaDB starts correctly.' 29 | -------------------------------------------------------------------------------- /centos-repo-builder/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xeu 3 | if [[ $# -eq 0 ]]; then 4 | echo "Usage: $0 [-bd] " 5 | exit 0 6 | fi 7 | builddep=0 8 | debug=0 9 | while getopts "bd" opt;do 10 | case $opt in 11 | b ) 12 | builddep=1 13 | ;; 14 | d ) 15 | debug=1 16 | ;; 17 | esac 18 | done 19 | shift $((OPTIND-1)) 20 | cd @REPO_DIR@ 21 | spec=$1 22 | [[ $builddep -eq 1 ]] && sudo /usr/bin/yum-builddep $spec 23 | 24 | if [[ debug -eq 1 ]];then 25 | echo "Content of ~/..rpmmacros" > /dev/stderr 26 | cat ~/.rpmmacros > /dev/stderr 27 | fi 28 | spectool -R -g $spec 29 | rpmbuild -ba $spec 30 | DistroDir=@REPO_DIR@/epel-@CENTOS_VERSION@ 31 | Nvr=$(rpm -q --qf '%{nvr}' --specfile $spec) 32 | Arch=$(rpm -q --qf '%{arch}' --specfile $spec) 33 | if [[ $Arch = "noarch" ]] ;then 34 | mv -f $DistroDir/noarch/* $DistroDir/x86_64 35 | rm -fr $DistroDir/noarch 36 | mkdir -p $DistroDir/i386 37 | cd $DistroDir/i386 38 | rm -f *.noarch.rpm 39 | ln -s ../x86_64/*.noarch.rpm . 40 | cd - 41 | fi 42 | cd $DistroDir 43 | for archDir in SRPMS x86_64 i386 ;do 44 | createrepo --update --database --verbose --delta $archDir 45 | done 46 | 47 | 48 | -------------------------------------------------------------------------------- /zanata-server/common: -------------------------------------------------------------------------------- 1 | # Default settings and functions for the scripts 2 | 3 | # JBoss ports 4 | : ${ZANATA_PORT:=8080} 5 | : ${ZANATA_DEBUG_PORT:=8787} 6 | : ${ZANATA_MGMT_PORT:=9990} 7 | 8 | # default database settings value 9 | : ${ZANATA_MYSQL_DATABASE:=zanata} 10 | : ${ZANATA_MYSQL_USER:=zanata} 11 | : ${ZANATA_MYSQL_PASSWORD:=password} 12 | 13 | # Mail settings 14 | : ${ZANATA_MAIL_HOST:=localhost} 15 | : ${ZANATA_MAIL_PORT:=25} 16 | # MAIL_USERNAME and MAIL_PASSWORD can not be empty as they are used in wildfly standalone-full.xml 17 | # If the smtp server does not require authentication, these single space values will be used 18 | SINGLE_SPACE=" " 19 | : "${ZANATA_MAIL_USERNAME:=SINGLE_SPACE}" 20 | : "${ZANATA_MAIL_PASSWORD:=SINGLE_SPACE}" 21 | : ${ZANATA_MAIL_TLS:=false} 22 | : ${ZANATA_MAIL_SSL:=false} 23 | 24 | # default docker network to join 25 | : ${ZANATA_DOCKER_NETWORK:=zanata-network} 26 | 27 | function ensure_docker_network() { 28 | # check if the docker network is already created 29 | if docker network ls | grep -w ${ZANATA_DOCKER_NETWORK} 30 | then 31 | echo "will use docker network $ZANATA_DOCKER_NETWORK" 32 | else 33 | echo "creating docker network $ZANATA_DOCKER_NETWORK" 34 | docker network create ${ZANATA_DOCKER_NETWORK} 35 | fi 36 | } 37 | -------------------------------------------------------------------------------- /zanata-server/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "2.1" 2 | services: 3 | zanatadb: 4 | image: "mariadb:10.1" 5 | restart: on-failure 6 | container_name: "zanatadb" 7 | command: "--character-set-server=utf8 --collation-server=utf8_general_ci" 8 | volumes: 9 | - zanata-db:/var/lib/mysql:Z 10 | environment: 11 | - MYSQL_RANDOM_ROOT_PASSWORD=yes 12 | - MYSQL_USER=${ZANATA_MYSQL_USER} 13 | - MYSQL_PASSWORD=${ZANATA_MYSQL_PASSWORD} 14 | - MYSQL_DATABASE=${ZANATA_MYSQL_DATABASE} 15 | healthcheck: 16 | test: ["CMD", "mysqladmin", "ping", "--silent"] 17 | zanata: 18 | image: "zanata/server:$ZANATA_VERSION" 19 | container_name: "zanata" 20 | ports: 21 | - "$ZANATA_PORT:8080" 22 | volumes: 23 | - zanata-files:/var/lib/zanata 24 | depends_on: 25 | zanatadb: 26 | condition: service_healthy 27 | environment: 28 | - ZANATA_HOME=/var/lib/zanata 29 | - DB_HOSTNAME=zanatadb 30 | - DB_SCHEMA=${ZANATA_MYSQL_DATABASE} 31 | - DB_USERNAME=${ZANATA_MYSQL_USER} 32 | - DB_PASSWORD=${ZANATA_MYSQL_PASSWORD} 33 | - DB_PORTNUMBER=3306 34 | - MAIL_HOST=${ZANATA_MAIL_HOST} 35 | - MAIL_PORT=${ZANATA_MAIL_PORT} 36 | - MAIL_USERNAME=${ZANATA_MAIL_USERNAME} 37 | - MAIL_PASSWORD=${ZANATA_MAIL_PASSWORD} 38 | - MAIL_TLS=${ZANATA_MAIL_TLS} 39 | - MAIL_SSL=${ZANATA_MAIL_SSL} 40 | volumes: 41 | zanata-files: 42 | zanata-db: 43 | -------------------------------------------------------------------------------- /centos-repo-builder/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM centos:@CENTOS_VERSION@ 2 | ARG CENTOS_VERSION=@CENTOS_VERSION@ 3 | ARG USER=builder 4 | ARG UID=1000 5 | ARG REPO_DIR="/repo" 6 | ARG RPMBUILD_TOPDIR="/rpmbuild" 7 | ARG RPMBUILD_SOURCEDIR="/rpmbuild/SOURCES" 8 | 9 | ## Override this if you want to test zanata-docker-files pull requests 10 | ARG BRANCH=master 11 | 12 | LABEL build="20180111" \ 13 | description="Build EPEL RPMs and create repository for Fedora People repository" 14 | 15 | ENV EXTRA_PACKAGES="java-1.8.0-openjdk-devel" 16 | 17 | ENTRYPOINT ["/home/builder/build"] 18 | 19 | RUN yum install -y createrepo rpm-build rpmdevtools sudo yum-utils $EXTRA_PACKAGES && yum clean all 20 | 21 | # create the user and home 22 | RUN useradd -m -G wheel -d /home/builder -u $UID $USER &&\ 23 | mkdir -p $REPO_DIR $RPMBUILD_SOURCEDIR $RPMBUILD_TOPDIR &&\ 24 | chown -R $USER $REPO_DIR $RPMBUILD_SOURCEDIR $RPMBUILD_TOPDIR &&\ 25 | echo "$USER ALL=(ALL) NOPASSWD: /usr/bin/yum-builddep" >> /etc/sudoers.d/$USER &&\ 26 | echo "Defaults lecture = never" >> /etc/sudoers.d/lecture 27 | 28 | VOLUME $REPO_DIR $RPMBUILD_SOURCEDIR 29 | 30 | WORKDIR /home/builder 31 | ADD "https://raw.githubusercontent.com/zanata/zanata-docker-files/$BRANCH/centos-repo-builder/_rpmmacros" .rpmmacros 32 | ADD "https://raw.githubusercontent.com/zanata/zanata-docker-files/$BRANCH/centos-repo-builder/build" build 33 | RUN chown $USER .rpmmacros build && chmod 755 build 34 | 35 | USER $USER 36 | 37 | ## Use @""CENTOS_VERSION@ to avoid it beening replaced by image-make 38 | RUN for f in .rpmmacros build ; do\ 39 | sed -i -e "s|@""CENTOS_VERSION@|$CENTOS_VERSION|g" $f &&\ 40 | sed -i -e "s|@REPO_DIR@|$REPO_DIR|g" $f &&\ 41 | sed -i -e "s|@RPMBUILD_TOPDIR@|$RPMBUILD_TOPDIR|g" $f &&\ 42 | sed -i -e "s|@RPMBUILD_SOURCEDIR@|$RPMBUILD_SOURCEDIR|g" $f ;\ 43 | done &&\ 44 | mkdir -p $RPMBUILD_TOPDIR 45 | 46 | -------------------------------------------------------------------------------- /zanata-server/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM jboss/wildfly:10.1.0.Final 2 | MAINTAINER "Ding-Yi Chen" 3 | 4 | EXPOSE 8080 5 | # Version should be assigned in build time 6 | # Take care editing the ZANATA_VERSION line: just version numbers, 7 | # otherwise runapp.sh cannot parse it. 8 | ARG ZANATA_VERSION=4.6.2 9 | ARG MYSQL_CONNECTOR_JAVA_VERSION=5.1.26 10 | 11 | # Database Setup 12 | ENV DB_HOSTNAME zanatadb 13 | ENV DB_PORTNUMBER 3306 14 | 15 | # MAIL_USERNAME and MAIL_PASSWORD can not be empty as they are used in wildfly standalone-full.xml. 16 | # If the smtp server does not require authentication, these single space values will be used 17 | ENV MAIL_HOST=localhost MAIL_USERNAME=' ' MAIL_PASSWORD=' ' 18 | 19 | # Fedora Containers Packaging may need this 20 | LABEL Name="zanata-platform"\ 21 | Version=$ZANATA_VERSION\ 22 | Release="2" 23 | 24 | USER root 25 | 26 | ENV ZANATA_HOME /var/lib/zanata 27 | RUN mkdir -p $ZANATA_HOME && chown -R jboss.jboss $ZANATA_HOME 28 | VOLUME $ZANATA_HOME 29 | 30 | # Make the image Openshift compatible by granting root group (not user) access to the necessary directories 31 | RUN chgrp -R 0 $ZANATA_HOME /opt/jboss/wildfly 32 | RUN chmod -R g+rw $ZANATA_HOME /opt/jboss/wildfly 33 | RUN find $ZANATA_HOME -type d -exec chmod g+x {} + 34 | RUN find /opt/jboss/wildfly -type d -exec chmod g+x {} + 35 | 36 | USER jboss 37 | 38 | RUN curl -L -o /opt/jboss/wildfly/standalone/deployments/mysql-connector-java.jar https://repo1.maven.org/maven2/mysql/mysql-connector-java/${MYSQL_CONNECTOR_JAVA_VERSION}/mysql-connector-java-${MYSQL_CONNECTOR_JAVA_VERSION}.jar 39 | 40 | # Zanata war 41 | RUN curl -L -o /opt/jboss/wildfly/standalone/deployments/ROOT.war \ 42 | https://github.com/zanata/zanata-platform/releases/download/platform-${ZANATA_VERSION}/zanata-war-${ZANATA_VERSION}.war \ 43 | && chmod o+rw /opt/jboss/wildfly/standalone/deployments/ROOT.war 44 | 45 | ADD conf/standalone.xml /opt/jboss/wildfly/standalone/configuration/ 46 | -------------------------------------------------------------------------------- /testDockerHelper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import unittest 3 | from DockerHelper import DockerImage 4 | 5 | class DockerImageTestCase(unittest.TestCase): 6 | def test_init(self): 7 | latest_image = DockerImage('zanata', 'server', 'latest') 8 | self.assertEqual(latest_image.tag_param, 'latest') 9 | self.assertFalse(hasattr(latest_image, 'version')) 10 | self.assertFalse(hasattr(latest_image, 'prerelease')) 11 | self.assertFalse(hasattr(latest_image, 'postrelease')) 12 | self.assertEqual(latest_image.final_tag, 'latest') 13 | self.assertEqual(latest_image.dockerfile_name, 'zanata-server/Dockerfile') 14 | 15 | vanilla_image = DockerImage('zanata', 'centos-repo-builder', '4.4.3') 16 | self.assertEqual(vanilla_image.tag_param, '4.4.3') 17 | self.assertEqual(vanilla_image.version, '4.4.3') 18 | self.assertFalse(hasattr(vanilla_image, 'prerelease')) 19 | self.assertFalse(hasattr(vanilla_image, 'postrelease')) 20 | self.assertEqual(vanilla_image.final_tag, '4.4.3') 21 | self.assertEqual(vanilla_image.dockerfile_name, 'centos-repo-builder/Dockerfile') 22 | 23 | postrelease_image = DockerImage('zanata', 'fedora-package', '4.4.3-2') 24 | self.assertEqual(postrelease_image.tag_param, '4.4.3-2') 25 | self.assertEqual(postrelease_image.version, '4.4.3') 26 | self.assertFalse(hasattr(postrelease_image, 'prerelease')) 27 | self.assertEqual(postrelease_image.postrelease, 2) 28 | self.assertEqual(postrelease_image.final_tag, '4.4.3-2') 29 | self.assertEqual(postrelease_image.dockerfile_name, 'fedora-package/Dockerfile') 30 | 31 | prerelease_image = DockerImage('zanata', 'server', '4.5.0-alpha-1') 32 | self.assertEqual(prerelease_image.tag_param, '4.5.0-alpha-1') 33 | self.assertEqual(prerelease_image.version, '4.5.0') 34 | self.assertEqual(prerelease_image.prerelease, 'alpha-1') 35 | self.assertFalse(hasattr(prerelease_image, 'postrelease')) 36 | self.assertEqual(prerelease_image.final_tag, '4.5.0-alpha-1') 37 | self.assertEqual(prerelease_image.dockerfile_name, 'zanata-server/Dockerfile') 38 | 39 | if __name__ == '__main__': 40 | unittest.main() 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Zanata Docker Files 2 | 3 | This repository includes files that are necessary to build docker images for Zanata. 4 | 5 | * [zanata-server](zanata-server/README.md): Zanata Server docker image. 6 | * [fedora-package](fedora-package/): For Fedora package review and build. 7 | * [image-make](image-make): Script to build non-zanata-server docker images . 8 | * [DockerHelper.py](DockerHelper.py): Script to build zanata-server docker images. 9 | 10 | For people who are in charge of publishing Zanata docker images, 11 | or interested in customizing Zanata docker images, read on. 12 | 13 | ## Publish Zanata Docker Images 14 | Publish means to build, tag and push images to registry. 15 | Note that only Zanata team is able to publish Zanata docker images 16 | 17 | Firstly, clone this repository and `cd` into the checked out directory. 18 | Then, login to docker from command line: 19 | ```sh 20 | docker login 21 | ``` 22 | If you do not have docker login yet, see section **Login to docker hub Account**. 23 | 24 | So far, we have `DockerHelper.py` (new script) for zanata-server, and 25 | `image-make` (old script) for everything else. 26 | 27 | ### Publish zanata-server Docker Images 28 | Use `DockerHelper.py` to publish the zanata-server images. 29 | 30 | For usage: 31 | ```sh 32 | ./DockerHelper.py -h 33 | ``` 34 | 35 | Usually, we can just publish images with 'auto' setting. 36 | ```sh 37 | ./DockerHelper.py publish server auto 38 | ``` 39 | It basically means use the latest released zanata-platform version and the next postrelease number. 40 | 41 | The **postrelease** number is the number that indicates the changes on the `zanata-docker-files` 42 | including changes `Dockerfile` and configuration associated with production docker images. 43 | It start as 1 when it is built for the first time for the released zanata-platform version. 44 | 45 | For example, `4.4.3-1` means it is the first docker image build against version 4.4.3. 46 | 47 | You can also specify the tag like: 48 | ```sh 49 | ./DockerHelper.py publish server 4.4.3-2 50 | ``` 51 | 52 | ### Publish other Docker Images 53 | Use `image-make` to build the non-zanata-server image. 54 | 55 | For usage: 56 | ```sh 57 | ./image-make -h 58 | ``` 59 | 60 | To publish the image from centos-repo-builder: 61 | ```sh 62 | ./image-make -p centos-repo-builder 63 | ``` 64 | 65 | ### Login to docker hub Account 66 | If you do not have a Docker Hub account, register at 67 | https://hub.docker.com/ then ask other Zanata team members to add you. 68 | 69 | You also need to login from the command line at your workstation, 70 | so you can push the image to Docker Hub. 71 | 72 | Run the following command and enter the docker registry username and password: 73 | ```sh 74 | docker login docker.io 75 | ``` 76 | 77 | 78 | _Note: These images are provided on a best-effort basis. Pull requests are most welcome_ 79 | 80 | Please report any issues in Zanata's bug tracker: https://zanata.atlassian.net/ 81 | -------------------------------------------------------------------------------- /centos-repo-builder/run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ### NAME 3 | ### run - run the centos-repo-builder 4 | ### 5 | ### SYNOPSIS 6 | ### run [Options] [-b] 7 | ### 8 | ### DESCRIPTION 9 | ### This program builds RPMs from a given SPEC file and update 10 | ### yum/dnf repodata. 11 | ### 12 | ### is the CentOS version you like to build from. 13 | ### Like 7 to build from CentOS 7. 14 | ### 15 | ### is the RPM SPEC filename. Currently, the SPEC file 16 | ### need to be in repoDir. 17 | ### 18 | ### is the directory that will host repository data and 19 | ### RPM files. is also a volume for docker. 20 | ### 21 | 22 | set -eu 23 | shopt -s globstar 24 | ScriptDir=$(dirname $(realpath $0)) 25 | ProgramName=$(basename $0) 26 | 27 | ##=== function definition Start === 28 | ## Get EXIT_STATUS and other environment variables from zanata-scripts 29 | source <(curl -q https://raw.githubusercontent.com/zanata/zanata-scripts/master/zanata-env.sh) 30 | 31 | zanata_help_raw(){ 32 | local script="$1" 33 | [ -z "$script" ] && script=$0 34 | sed -r -n -e '/^### ?/ {s|^### ?||p}' $script 35 | } 36 | ##=== function definition End === 37 | 38 | DockerRunOptArray=() 39 | ## Arguments for /home/builder/build 40 | ArgumentArray=() 41 | ContainerName= 42 | 43 | ### 44 | ### Options 45 | while getopts "hbdn:o:rs:" opt;do 46 | case $opt in 47 | ### -h: Show detail help. 48 | h ) 49 | zanata_help_raw $0 50 | exit ${EXIT_OK} 51 | ;; 52 | ### -b: Install build dependencies in docker 53 | ### It runs sudo yum-builddep to install build 54 | ### dependencies in docker. 55 | b ) 56 | ArgumentArray+=( -b ) 57 | ;; 58 | ### -d: Debug mode 59 | ### It will list .rpmmacros and some other debug information. 60 | d ) 61 | ArgumentArray+=( -d ) 62 | ;; 63 | ### -n : Container name 64 | ### Default: centos-builder 65 | n ) 66 | ContainerName=$OPTARG 67 | ;; 68 | ### -o : Options for docker-run 69 | o ) 70 | DockerRunOptArray+=( ${OPTARG} ) 71 | ;; 72 | ### -r Remove the container after execution 73 | r ) 74 | DockerRunOptArray+=( --rm ) 75 | ;; 76 | ### -s : Directory for RPM sourcedir 77 | s ) 78 | DockerRunOptArray+=( -v $(realpath $OPTARG):/rpmbuild/SOURCES:Z ) 79 | ;; 80 | esac 81 | done 82 | shift $((OPTIND-1)) 83 | 84 | if [[ $# -lt 3 ]]; then 85 | zanata_help_raw $0 86 | exit ${EXIT_FATAL_INVALID_OPTIONS} 87 | fi 88 | 89 | CentosVersion=$1 90 | SpecFile=$2 91 | RepoDir=$(realpath $3) 92 | shift 3 93 | [[ -z ${ContainerName} ]] && ContainerName="centos${CentosVersion}-builder" 94 | 95 | docker run ${DockerRunOptArray[@]:-} -it --name $ContainerName -v $RepoDir:/repo:Z docker.io/zanata/centos-repo-builder:$CentosVersion ${ArgumentArray[@]:-} $SpecFile $@ 96 | 97 | ### 98 | ### EXIT_STATUS 99 | ### See https://github.com/zanata/zanata-scripts/blob/master/zanata-env.sh 100 | -------------------------------------------------------------------------------- /zanata-server/README.md: -------------------------------------------------------------------------------- 1 | This document shows how to set up a Zanata instance using docker. 2 | 3 | The helper scripts use docker data volumes and docker container network, therefore docker >= 1.9 4 | is required. 5 | 6 | The following instructions assume that you have cloned this repository 7 | and opened a terminal in the zanata-server directory. 8 | 9 | ## Build Image 10 | The latest zanata-server image is available as `docker.io/zanata/server:latest`, 11 | skip to next section if you just want to use zanata-server. 12 | 13 | To build the latest released Zanata server, run the following command: 14 | ```sh 15 | $ docker build -t zanata/server . 16 | ``` 17 | 18 | You can also specify the version you want to build. For example, you can build version 4.2.1 with the following command: 19 | ```sh 20 | $ docker build -t zanata/server:4.4.3 --build-arg=ZANATA_VERSION=4.4.3 . 21 | ``` 22 | 23 | Note that for older versions, you may need to edit `standalone.xml` to make Zanata work. 24 | 25 | ## Setup Environment 26 | These environment variables are used in the helper scripts. 27 | Override them to suit your needs. 28 | 29 | * `ZANATA_DAEMON_MODE`: 30 | If `1`, the Zanata runs as daemon; 31 | otherwise, it runs in the foreground and prints its log directly to the console. (Default: empty ) 32 | * `ZANATA_DOCKER_NETWORK`: docker network that Zanata containers belong. (Default: `docker-network`) 33 | * `ZANATA_MGMT_PORT`: Wildfly management port. (Default: 9990) 34 | * `ZANATA_MYSQL_DATABASE`: Zanata uses this database name in MariaDB. (Default: `zanata`) 35 | * `ZANATA_MYSQL_USER`: Zanata uses this username to access database in MariaDB. (Default: `zanata`) 36 | * `ZANATA_MYSQL_PASSWORD`: Zanata uses this password to access database in MariaDB. (Default: `password`) 37 | * `ZANATA_PORT`: Zanata listens on this port on the host. (Default: `8080`) 38 | * `ZANATA_VERSION`: Zanata docker version to be run. (Default: `latest`) 39 | * `ZANATA_MAIL_HOST`: SMTP host Zanata will send mails to. (Default: `localhost`) 40 | * `ZANATA_MAIL_PORT`: SMTP port Zanata will send mails to. (Default: `25`) 41 | * `ZANATA_MAIL_USERNAME`: SMTP Username for mail authentication (Default: `username`) 42 | * `ZANATA_MAIL_PASSWORD`: SMTP Password for mail authentication (Default: `password`) 43 | * `ZANATA_MAIL_TLS`: Enable TLS transport for SMTP (Default: `false`) 44 | * `ZANATA_MAIL_SSL`: Enable SSL transport for SMTP (usually used on Port 465) (Default: `false`) 45 | 46 | ## Run Zanata as docker container 47 | To run Zanata as docker container, set up your config as environment variables (see above) in a .env file. 48 | 49 | Then simply run: 50 | ``` 51 | ./runapp.sh 52 | ``` 53 | 54 | If the data containers are not running, this will start the data containers as well. 55 | See `rundb.sh` for the invocation detail. 56 | 57 | 58 | ## Create an admin user 59 | 60 | At this point, you have a running Zanata instance... with no users created (!) 61 | 62 | To create an admin user, you can connect to the database server and run the script at `conf/admin-user-setup.sql` like this: 63 | 64 | ```sh 65 | $ DB_IP=$(docker inspect --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' zanatadb) 66 | $ mysql --protocol=tcp -h $DB_IP -u zanata -p zanata < conf/admin-user-setup.sql 67 | ``` 68 | 69 | where `DB_IP` is IP address of `zanatadb`. You will need to type the Zanata Maridb password 70 | (defined in `ZANATA_MYSQL_PASSWORD`, default is `password`). 71 | 72 | This won't work if you haven't installed mysql locally and the zanatadb port isn't exposed. 73 | To run the script alternatively direct inside of the container please first copy the admin-user-setup.sql file to the container and then run mysql inside of the container: 74 | 75 | ```sh 76 | $ docker cp conf/admin-user-setup.sql zanatadb:/tmp 77 | $ docker exec -it zanatadb bash -c "mysql -u zanata --password=password zanata < /tmp/admin-user-setup.sql" 78 | ``` 79 | 80 | ## Access Zanata 81 | Open a browser and head to `http://HOST:PORT/zanata`, where `PORT` is the port specified in `ZANATA_HOST_PORT` (default `8080`), and `HOST` is the docker host's address (this might be `localhost` or some other IP address if running on OSX for example). 82 | 83 | In other words, if you run Zanata in your local machine and change nothing, 84 | you can reach Zanata at `http://localhost:8080/zanata` 85 | 86 | ## DockerHub 87 | 88 | The DockerHub site for Zanata images is here: 89 | https://hub.docker.com/r/zanata/server/ 90 | -------------------------------------------------------------------------------- /zanata-server/runapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -eu 2 | 3 | ScriptFile=$(realpath ${BASH_SOURCE[0]}) 4 | ScriptDir=$(dirname $ScriptFile) 5 | source $ScriptDir/common 6 | 7 | # misc 8 | JBOSS_DEPLOYMENT_VOLUME=/opt/jboss/wildfly/standalone/deployments/ 9 | 10 | if [ -n "${ZANATA_VERSION-}" ];then 11 | ## Use the version from set environment ZANATA_VERSION 12 | ZanataVer=$ZANATA_VERSION 13 | else 14 | ## Use the latest version (not necessarily the version defined in the Dockerfile) 15 | ZanataVer=latest 16 | fi 17 | 18 | declare -a DockerOptArray 19 | while getopts "e:p:n:hl:" opt; do 20 | case ${opt} in 21 | e) 22 | echo "==== use $OPTARG as mail host ====" 23 | ZANATA_MAIL_HOST=$OPTARG 24 | ;; 25 | l) 26 | echo "==== provide SMTP host login (username:password) ====" 27 | # set the internal field separator (IFS) variable, and then let it parse into an array. 28 | # When this happens in a command, then the assignment to IFS only takes place to that single command's environment (to read ). 29 | # It then parses the input according to the IFS variable value into an array 30 | IFS=':' read -ra CREDENTIAL <<< "$OPTARG" 31 | if [ ${#CREDENTIAL[@]} -ne 2 ]; then 32 | echo "Must provide SMTP credentials in username:password format (colon separated)" 33 | exit 1 34 | fi 35 | ZANATA_MAIL_USERNAME=${CREDENTIAL[0]} 36 | ZANATA_MAIL_PASSWORD=${CREDENTIAL[1]} 37 | DockerOptArray+=( -e MAIL_USERNAME="${ZANATA_MAIL_USERNAME}" -e MAIL_PASSWORD="${ZANATA_MAIL_PASSWORD}" ) 38 | ;; 39 | p) 40 | echo "===== set JBoss port offset to $OPTARG =====" 41 | if [ "$OPTARG" -eq "$OPTARG" ] 2>/dev/null 42 | then 43 | ZANATA_PORT=$(($OPTARG + 8080)) 44 | ZANATA_DEBUG_PORT=$(($OPTARG + 8787)) 45 | ZANATA_MGMT_PORT=$(($OPTARG + 9090)) 46 | echo "===== Zanata HTTP port : $ZANATA_PORT" 47 | echo "===== Debug port : $ZANATA_DEBUG_PORT" 48 | echo "===== Management port : $ZANATA_MGMT_PORT" 49 | else 50 | echo "===== MUST provide an integer as argument =====" 51 | exit 1 52 | fi 53 | ;; 54 | n) 55 | echo "===== set docker network to $OPTARG =====" 56 | ZANATA_DOCKER_NETWORK=$OPTARG 57 | ;; 58 | h) 59 | echo "======== HELP =========" 60 | echo "-e : SMTP mail host" 61 | echo "-l : SMTP login: username and password separated by colon" 62 | echo "-p : set JBoss port offset" 63 | echo "-n : will connect container to given docker network (default is $ZANATA_DOCKER_NETWORK)" 64 | echo "-h : display help" 65 | exit 66 | ;; 67 | \?) 68 | echo "Invalid option: -${OPTARG}. Use -h for help" >&2 69 | exit 1 70 | ;; 71 | esac 72 | done 73 | 74 | ## Checking Variables 75 | if [[ -z ${ZANATA_MAIL_HOST:-} ]];then 76 | echo "[ERROR] Undefined mail host. Use Option -e or environment variable ZANATA_MAIL_HOST=" > /dev/stderr 77 | exit 1 78 | fi 79 | 80 | ensure_docker_network 81 | 82 | ## Setup DB container if not running 83 | if [ -z $(docker ps -aq -f name=zanatadb -f status=running) ]; then 84 | $ScriptDir/rundb.sh 85 | fi 86 | ZANATA_DB_HOST=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' zanatadb) 87 | 88 | echo "Preparing container for Zanata ($ZanataVer)" > /dev/stderr 89 | ## Create zanata-files volume if it is missing 90 | if ! (docker volume ls -q | grep zanata-files) ; then 91 | docker volume create --name zanata-files 92 | fi 93 | 94 | DockerOptArray+=( --name zanata 95 | -e DB_USERNAME="${ZANATA_MYSQL_USER}" \ 96 | -e DB_PASSWORD="${ZANATA_MYSQL_PASSWORD}" \ 97 | -e DB_SCHEMA="${ZANATA_MYSQL_DATABASE}" \ 98 | -e DB_HOSTNAME="${ZANATA_DB_HOST}" \ 99 | -e MAIL_HOST="${ZANATA_MAIL_HOST}" \ 100 | -e MAIL_PORT="${ZANATA_MAIL_PORT}" \ 101 | -e MAIL_USERNAME="${ZANATA_MAIL_USERNAME:= }" \ 102 | -e MAIL_PASSWORD="${ZANATA_MAIL_PASSWORD:= }" \ 103 | -e MAIL_TLS="${ZANATA_MAIL_TLS}" \ 104 | -e MAIL_SSL="${ZANATA_MAIL_SSL}" \ 105 | -e ZANATA_HOME=/var/lib/zanata \ 106 | -e ZANATA_MGMT=${ZANATA_MGMT_PORT} \ 107 | --net ${ZANATA_DOCKER_NETWORK} \ 108 | -p ${ZANATA_PORT}:8080 \ 109 | -p ${ZANATA_DEBUG_PORT}:8787 \ 110 | -v zanata-files:/var/lib/zanata:Z \ 111 | ) 112 | 113 | ## If specified ZANATA_DAEMON_MODE=1, it runs Zanata as daemon, 114 | ## Otherwise it will remove the container after program exit. 115 | if [ "${ZANATA_DAEMON_MODE-}" = "1" ];then 116 | DockerOptArray+=( -d ) 117 | else 118 | DockerOptArray+=( --rm -it ) 119 | fi 120 | 121 | docker run ${DockerOptArray[@]} zanata/server:$ZanataVer 122 | -------------------------------------------------------------------------------- /image-make: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ### NAME 3 | ### image-make - create, tag and push docker image 4 | ### 5 | ### SYNOPSIS 6 | ### image-make [Options] 7 | ### 8 | ### DESCRIPTION 9 | ### This program builds, tag, and push docker images to docker registry as: 10 | ### zanata/: 11 | ### 12 | ### The can be any of sub-directories of this project that 13 | ### contains a Dockerfile. 14 | ### 15 | ### Specify with -t . 16 | ### If -t is not specified, default is 'latest' 17 | ### Note that for DockerName "centos-repo-builder", beside just tag as , 18 | ### you also get -. For example, specified 'by default, you get 19 | ### following tags for centos-repo-builder: 20 | ### 21 | ### latest, 7-latest, 6-latest 22 | ### 23 | ### Note that centos-repo-builder:7 means centos-repo-builder:7-latest, and 24 | ### centos-repo-builder:6 is also similar. 25 | ### 26 | ### Also note that this script assumes that you already have an docker registry 27 | ### account and have logged in from the command line at your workstation. 28 | ### Refer README.md for instruction. 29 | ### 30 | ### ARGUMENTS 31 | ### : Name of the docker to be build 32 | ### 33 | ### ENVIRONMENT 34 | ### ZANATA_DOCKER_PUSH_REGISTRY: Docker registry for pushing 35 | ### Note that you should configure /etc/sysconfig/docker to add 36 | ### the registry. 37 | ### Default: docker.io 38 | : ${ZANATA_DOCKER_PUSH_REGISTRY:=docker.io} 39 | set -eu 40 | 41 | ### 42 | shopt -s globstar 43 | ScriptDir=$(dirname $(readlink -q -f $0)) 44 | ProgramName=$(basename $0) 45 | 46 | ##=== function definition Start === 47 | ## Get EXIT_STATUS and other environment variables from zanata-scripts 48 | source <(curl -q https://raw.githubusercontent.com/zanata/zanata-scripts/master/zanata-env.sh) 49 | 50 | echo_stderr(){ 51 | echo "$@" > /dev/stderr 52 | } 53 | 54 | zanata_help_raw(){ 55 | local script="$1" 56 | [ -z "$script" ] && script=$0 57 | sed -r -n -e '/^### ?/ {s|^### ?||p}' $script 58 | } 59 | 60 | ## run_command [args ... ] 61 | ## On Dry-run mode, just show the command, 62 | ## otherwise run the command. 63 | run_command(){ 64 | if [[ ${DryRunMode:-} -eq 1 ]];then 65 | ExitCode=$EXIT_OK 66 | else 67 | set -x 68 | "$@" 69 | ExitCode=$? 70 | set +x 71 | fi 72 | } 73 | 74 | docker_tag_image(){ 75 | local image=$1 76 | local dockerName=$2 77 | local tag=$3 78 | 79 | if [[ $image != $RepoName/$dockerName:$tag ]] ;then 80 | run_command docker tag $image $RepoName/$dockerName:$tag 81 | fi 82 | run_command docker tag $image $ZANATA_DOCKER_PUSH_REGISTRY/$RepoName/$dockerName:$tag 83 | } 84 | 85 | CENTOS_VERSION_ARRAY=( 7 6) 86 | CENTOS_VERSION_DEFAULT=7 87 | ##=== parsing Start === 88 | declare -a TagArray=() 89 | declare -a ExtraOptionArray=() 90 | DockerfileSource= 91 | RepoName=zanata 92 | ReleaseMode=0 93 | BuildOptions= 94 | IsPush=0 95 | ImageTag= 96 | IgnoreError= 97 | ## BaseVersion is the version without qualifier. e.g. BaseVersion of 4.4.0-alpha-1 is 4.4.0 98 | BaseVersion= 99 | ## ArtifactVersion is the actual version. e.g. 4.4.0-alpha-1 100 | ArtifactVersion= 101 | 102 | ### OPTIONS 103 | while getopts "hb:it:pr:" opt;do 104 | case $opt in 105 | ### -h: Show detail help. 106 | h ) 107 | zanata_help_raw $0 108 | exit ${EXIT_OK} 109 | ;; 110 | ### -b: docker build options 111 | ### e.g. -b '--build-arg CENTOS_VERSION=6' 112 | b ) 113 | BuildOptions=${OPTARG} 114 | ;; 115 | ### -i: Ignore error 116 | ### Proceed the task. 117 | i ) 118 | IgnoreError=1 119 | ;; 120 | ### -t: docker image tags. Can specify multiple times for multiple tags. 121 | ### E.g. -t 'latest' -t '4.0.0' -t '4.0.0-1' 122 | ### If no other tags are specified, the image is tagged as 'latest' 123 | t ) 124 | TagArray+=( ${OPTARG} ) 125 | ;; 126 | ### -p: Also push the image 127 | p ) 128 | IsPush=1 129 | ;; 130 | ### 131 | ### -r : Release docker image as zanata/: 132 | ### For normal release, just put version number. e.g. '4.3.0' 133 | ### If you change Dockerfile after a released version, put the 134 | ### sequence number after version, e.g. '4.3.0-1' 135 | ### 136 | ### You can also put pre-release tag like 4.4.0-0.alpha-2, 137 | ### This will download corresponding WAR file (e.g. zanata-war-4.4.0-alpha-2.war) 138 | ### and make the docker image (e.g. zanata/server:4.4.0-0.alpha-2) 139 | ### 140 | ### This does following: 141 | ### 1. Update ZANATA_VERSION in Dockerfile. 142 | ### (Sequence number will NOT be included) 143 | ### 2. Make a commit to zanata-docker-file 144 | ### with message: '[release] Image zanata/: is released' 145 | ### Note that this commit will NOT be pushed to zanata-docker-file automatically. 146 | ### 3. Build and tag the image as zanata/: 147 | ### 4. Push the image to DockerHub 148 | ### 149 | ### You can also put pre-release tag like 4.4.0-alpha-2, 150 | ### This will download corresponding WAR file (e.g. zanata-war-4.4.0-alpha-2.war) 151 | ### and make the docker image (e.g. zanata/server:4.4.0-alpha-2) 152 | ### However, 'latest' won't be tag to pre-release images. 153 | r ) 154 | ImageTag=${OPTARG} 155 | TagArray+=( ${ImageTag} ) 156 | BaseVersion=${ImageTag%%-*} 157 | Qualifier=$(sed -r -n -e 's/^[^-]*-(.*)$/\1/p'<<<$ImageTag) 158 | if [[ $Qualifier == [abrmABRM]* ]]; then 159 | ## Cover the pre-release qualifiers such as alpha, beta, rc, milestone 160 | ArtifactVersion="$BaseVersion-$Qualifier" 161 | else 162 | TagArray+=( latest ) 163 | ArtifactVersion=$BaseVersion 164 | fi 165 | IsPush=1 166 | ReleaseMode=1 167 | echo "ArtifactVersion: $ArtifactVersion" > /dev/stderr 168 | echo "TagArray: ${TagArray[@]}" > /dev/stderr 169 | ;; 170 | * ) 171 | failed ${EXIT_FATAL_INVALID_OPTIONS} "$opt" 172 | ;; 173 | esac 174 | done 175 | shift $((OPTIND-1)) 176 | 177 | ## Check DockerName 178 | if [[ -z ${1-} ]];then 179 | echo_stderr "[FATAL] not specified" 180 | echo_stderr "Use '$0 -h' for help" 181 | exit $EXIT_FATAL_INVALID_OPTIONS 182 | fi 183 | DockerName=$1 184 | 185 | case $DockerName in 186 | server ) 187 | DockerfileSource=zanata-server 188 | ;; 189 | centos-repo-builder ) 190 | ;; 191 | * ) 192 | if [[ ! -r $DockerName/Dockerfile ]]; then 193 | echo_stderr "[FATAL] DockerName $DockerName is invalid" 194 | exit $EXIT_FATAL_INVALID_OPTIONS 195 | fi 196 | DockerfileSource=$DockerName 197 | ;; 198 | esac 199 | 200 | if [ -z "${TagArray-}" ];then 201 | TagArray=( latest ) 202 | fi 203 | 204 | ## Remove duplicate tags 205 | TagArray=($(tr ' ' '\n' <<<${TagArray[@]} | sort -u)) 206 | 207 | ##=== Update Version when releasing 208 | if [[ $ReleaseMode -eq 1 ]]; then 209 | cd $ScriptDir 210 | 211 | ## Does Docker hub already has the tag? 212 | tagStr=$(curl -s -S "https://registry.hub.docker.com/v2/repositories/$RepoName/$DockerName/tags/" | jq '.results[] | select(.name == "'$ImageTag'" )') 213 | if [[ -n $tagStr ]];then 214 | if [[ $IgnoreError -eq 0 ]];then 215 | echo_stderr "Docker hub already has $RepoName/$DockerName:$ImageTag" 216 | exit $EXIT_RETURN_FALSE 217 | fi 218 | fi 219 | sed -i -e 's/^ARG ZANATA_VERSION=.*$/ARG ZANATA_VERSION='$ArtifactVersion'/' $DockerfileSource/Dockerfile 220 | if ! git diff --exit-code; then 221 | git commit -a -m "[release] Image zanata/$DockerName:$ImageTag is released" 222 | elif [[ $IgnoreError -eq 0 ]];then 223 | echo_stderr "Docker file is already updated" 224 | exit $EXIT_RETURN_FALSE 225 | fi 226 | cd - 227 | fi 228 | 229 | ##=== make Start === 230 | for tag in "${TagArray[@]}";do 231 | case $DockerName in 232 | centos-repo-builder ) 233 | for CENTOS_VERSION in "${CENTOS_VERSION_ARRAY[@]}" ;do 234 | Image="$RepoName/$DockerName:$CENTOS_VERSION-$tag" 235 | run_command docker build $BuildOptions --build-arg "CENTOS_VERSION=$CENTOS_VERSION" -t $Image - \ 236 | <<< "$(sed -e "s/@CENTOS_VERSION@/$CENTOS_VERSION/g" $ScriptDir/$DockerName/Dockerfile)" 237 | 238 | ## Stage Tag 239 | docker_tag_image $Image $DockerName "$CENTOS_VERSION-$tag" 240 | if [[ $CENTOS_VERSION = $CENTOS_VERSION_DEFAULT ]];then 241 | docker_tag_image $Image $DockerName $tag 242 | fi 243 | if [[ $tag = 'latest' ]];then 244 | docker_tag_image $Image $DockerName $CENTOS_VERSION 245 | fi 246 | 247 | ## Stage push 248 | if [ $IsPush -eq 1 ];then 249 | run_command docker push $ZANATA_DOCKER_PUSH_REGISTRY/$Image 250 | if [[ $CENTOS_VERSION = $CENTOS_VERSION_DEFAULT ]];then 251 | run_command docker push $ZANATA_DOCKER_PUSH_REGISTRY/$DockerName:$tag 252 | fi 253 | if [[ $tag = 'latest' ]];then 254 | run_command docker push $ZANATA_DOCKER_PUSH_REGISTRY/$DockerName:$CENTOS_VERSION 255 | fi 256 | fi 257 | done 258 | ;; 259 | * ) 260 | Image=$RepoName/$DockerName:$tag 261 | run_command docker build $BuildOptions -t $Image $DockerfileSource 262 | run_command docker tag $Image $ZANATA_DOCKER_PUSH_REGISTRY/$Image 263 | if [ $IsPush -eq 1 ];then 264 | run_command docker push $ZANATA_DOCKER_PUSH_REGISTRY/$Image 265 | fi 266 | ;; 267 | esac 268 | done 269 | 270 | ### 271 | ### EXIT_STATUS 272 | ### See https://github.com/zanata/zanata-scripts/blob/master/zanata-env.sh 273 | -------------------------------------------------------------------------------- /DockerHelper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Docker Helper functions 3 | It contains docker tag query functions and Dockerfile update function. 4 | Run ./DockerHelper --help or ./DockerHelper --help for 5 | detail help.""" 6 | 7 | from typing import List, Any # pylint: disable=unused-import 8 | # We need to import 'List' and 'Any' for mypy to work 9 | import argparse 10 | import fileinput 11 | import json 12 | import logging 13 | import re 14 | import subprocess # nosec 15 | import sys 16 | import urllib2 17 | 18 | 19 | class GitHelper(object): 20 | "Helper functions for git" 21 | GIT_CMD = '/bin/git' 22 | 23 | @staticmethod 24 | def remote_get_latest_tag(repo_url, tag_glob='*'): 25 | # type: (str, str) -> str 26 | """Get latest (newest) tag from git remote 27 | Known Bug: If the tag 4.4.4 is newer than 4.5.0, 28 | then the 'latest' tag will be 4.4.4""" 29 | 30 | tag = subprocess.check_output( # nosec 31 | [GitHelper.GIT_CMD, 'ls-remote', '--tags', repo_url, 32 | 'refs/tags/' + tag_glob + '[^^{}]'] 33 | ).split()[-1].split('/')[-1] 34 | logging.info("latest tag of %s is %s", repo_url, tag) 35 | return tag 36 | 37 | @staticmethod 38 | def branch_get_current(): 39 | # type: () -> str 40 | """Return either current branch, or 'HEAD' if in detached mode 41 | This method assume you are already in correct directory""" 42 | return subprocess.check_output( # nosec 43 | [GitHelper.GIT_CMD, 'rev-parse', '--abbrev-ref', 'HEAD']) 44 | 45 | @staticmethod 46 | def branch_merge_detached(target_branch): 47 | # type: (str) -> None 48 | """Merge to target_branch if in git detached mode, or no-op 49 | This method assume you are already in correct directory""" 50 | commit_sha = subprocess.check_output( # nosec 51 | [GitHelper.GIT_CMD, 'rev-parse', 'HEAD']) 52 | tmp_branch = 'br-' + commit_sha 53 | if GitHelper.branch_get_current() == 'HEAD': 54 | subprocess.check_call( # nosec 55 | [GitHelper.GIT_CMD, 'branch', tmp_branch, commit_sha]) 56 | subprocess.check_call( # nosec 57 | [GitHelper.GIT_CMD, 'checkout', target_branch]) 58 | subprocess.check_call( # nosec 59 | [GitHelper.GIT_CMD, 'merge', tmp_branch]) 60 | subprocess.check_call( # nosec 61 | [GitHelper.GIT_CMD, 'branch', '-D', tmp_branch]) 62 | 63 | @staticmethod 64 | def push(target_branch): 65 | # type: (str) -> None 66 | "Git push to master if there is unpushed commits" 67 | if subprocess.call( # nosec 68 | [GitHelper.GIT_CMD, 'diff', '--exit-code', 'origin', 'HEAD'] 69 | ) != 0: 70 | # branch_merge_detached is needed in Jenkins 71 | # as it checkout as detached 72 | GitHelper.branch_merge_detached(target_branch) 73 | subprocess.check_call([ # nosec 74 | GitHelper.GIT_CMD, 'push', '--follow-tags', 75 | 'origin', 'master']) 76 | 77 | def __init__(self, repo_url, tag_prefix=''): 78 | # type: (str, str) -> None 79 | self.repo_url = repo_url 80 | self.latest_tag = GitHelper.remote_get_latest_tag( 81 | self.repo_url, tag_prefix+'*') 82 | self.latest_version = self.latest_tag[len(tag_prefix):] 83 | 84 | def __getitem__(self, key): 85 | # type: (str) -> str 86 | return self[key] 87 | 88 | 89 | class DockerImage(object): 90 | """This class contains information about Docker image tag and dockerfile 91 | tag: version-postrelease, version, or simply 'latest' 92 | dockerfile: path""" 93 | # pylint: disable=too-many-instance-attributes 94 | 95 | # Cmd full path 96 | DOCKER_CMD = '/bin/docker' 97 | 98 | DOCKER_NAME_DB = { 99 | 'server': { 100 | 'dir': 'zanata-server', 101 | 'url': 'https://github.com/zanata/zanata-platform', 102 | 'tag_prefix': 'platform-', 103 | } 104 | } 105 | 106 | @staticmethod 107 | def list_tags(repo_name, docker_name): 108 | # type: (str, str) -> List[str] 109 | """Return the name of tags as list""" 110 | tag_url = 'https://%s/%s/%s/tags/' % ( 111 | 'registry.hub.docker.com/v2/repositories', 112 | repo_name, docker_name) 113 | result = [] # type: List[str] 114 | while tag_url: 115 | logging.info("Getting tags from %s", tag_url) 116 | # Audited urlopen URL 117 | response = urllib2.urlopen(tag_url) # nosec 118 | logging.debug(response.info()) 119 | 120 | tags_json = json.load(response) 121 | result += [elem["name"] for elem in tags_json["results"]] 122 | tag_url = tags_json.get("next", "") 123 | return result 124 | 125 | @staticmethod 126 | def has_tag(repo_name, docker_name, tag): 127 | # type: (str, str, str) -> int 128 | """Whether the docker image has the given tag""" 129 | tags_list = DockerImage.list_tags(repo_name, docker_name) 130 | return tag in tags_list 131 | 132 | @staticmethod 133 | def next_postrelease(repo_name, docker_name, version): 134 | # type: (str, str, str) -> int 135 | "Next unused postrelease" 136 | prog = re.compile("^%s-([0-9]+)" % version) 137 | current_release = 0 138 | for tag in DockerImage.list_tags(repo_name, docker_name): 139 | matched = re.match(prog, tag) 140 | if not matched: 141 | continue 142 | if int(matched.group(1)) > current_release: 143 | current_release = int(matched.group(1)) 144 | return current_release + 1 145 | 146 | def __init__(self, repo_name, docker_name, tag_param): 147 | # type: (str, str, str) -> None 148 | # pylint: disable=too-many-instance-attributes 149 | """Properties: 150 | repo_name: repository name. e.g. 'zanata' 151 | docker_name: docker image name. e.g. 'server' 152 | tag_param: The tag parameter, it accepts either x.y.z-r or 'auto' 153 | version: e.g. 4.4.3 154 | prerelesae: e.g. alpha-1 155 | postrelease: e.g. 2 156 | final_tag: Final resolved tag, like 4.4.3-2""" 157 | 158 | self.repo_name = repo_name 159 | # Dockerfile 160 | self.docker_name = docker_name 161 | if docker_name in DockerImage.DOCKER_NAME_DB: 162 | dockerfile_dir = DockerImage.DOCKER_NAME_DB[docker_name]['dir'] 163 | else: 164 | dockerfile_dir = docker_name 165 | 166 | self.dockerfile_name = "%s/Dockerfile" % dockerfile_dir 167 | 168 | self.tag_param = tag_param 169 | # Docker Tag 170 | match = re.match('^([0-9.]+)(-(.*))?', self.tag_param) 171 | if match: 172 | self.version = match.group(1) 173 | extra = match.group(3) 174 | if extra: 175 | if extra.isdigit(): 176 | self.postrelease = int(extra) 177 | self.final_tag = "%s-%d" % ( 178 | self.version, self.postrelease) 179 | else: 180 | # alpha or rc 181 | self.prerelease = extra 182 | self.final_tag = "%s-%s" % ( 183 | self.version, self.prerelease) 184 | else: 185 | self.final_tag = self.version 186 | 187 | elif self.tag_param == 'auto': 188 | if self.docker_name in DockerImage.DOCKER_NAME_DB: 189 | git_helper = GitHelper( 190 | DockerImage.DOCKER_NAME_DB[docker_name]['url'], 191 | DockerImage.DOCKER_NAME_DB[docker_name]['tag_prefix']) 192 | 193 | self.version = git_helper.latest_version 194 | self.postrelease = DockerImage.next_postrelease( 195 | repo_name, docker_name, self.version) 196 | else: 197 | logger.error("Unsupported docker_name %s", docker_name) 198 | sys.exit(EXIT_FATAL_INVALID_ARGUMENTS) 199 | self.final_tag = "%s-%d" % (self.version, self.postrelease) 200 | else: 201 | self.final_tag = self.tag_param 202 | self.image_name = "%s/%s:%s" % ( 203 | self.repo_name, self.docker_name, self.final_tag) 204 | 205 | def __getitem__(self, key): 206 | # type: (str) -> str 207 | return self[key] 208 | 209 | def dockerfile_update(self): 210 | # type: () -> None 211 | """Update the Dockerfile""" 212 | 213 | release = 1 if not hasattr(self, 'postrelease') else int(self.postrelease) 214 | 215 | dockerfile_file = fileinput.FileInput( 216 | [self.dockerfile_name], inplace=True, backup='.bak') 217 | for line in iter(dockerfile_file): 218 | if re.match(r'^ARG ZANATA_VERSION=.*$', line): 219 | sys.stdout.write( 220 | re.sub(r'^ARG ZANATA_VERSION=.*$', 221 | 'ARG ZANATA_VERSION=%s' % self.version, line)) 222 | elif re.match(r'\s*Release="([0-9]+)"', line): 223 | sys.stdout.write( 224 | re.sub(r'Release=".*"', 225 | 'Release="%d"' % release, line)) 226 | else: 227 | sys.stdout.write(line) 228 | 229 | sys.stdout.flush() 230 | dockerfile_file.close() 231 | 232 | 233 | # Exit Status 234 | EXIT_OK = 0 235 | EXIT_FATAL_INVALID_OPTIONS = 3 236 | EXIT_FATAL_INVALID_ARGUMENTS = 7 237 | EXIT_RETURN_FALSE = 40 238 | 239 | # Set logging 240 | logging.basicConfig(format='%(asctime)-15s [%(levelname)s] %(message)s') 241 | logger = logging.getLogger() 242 | logger.setLevel(logging.INFO) 243 | 244 | 245 | def get_tags(): 246 | # type: () -> None 247 | """Return the name of tags as list""" 248 | logging.info("get-tags for %s/%s", args.repo_name, args.docker_name) 249 | 250 | tags_list = DockerImage.list_tags(args.repo_name, args.docker_name) 251 | print('\n'.join(str(tag) for tag in tags_list)) 252 | 253 | 254 | def has_tag(): 255 | # type: () -> None 256 | """Whether the docker image has the given tag""" 257 | 258 | if DockerImage.has_tag(args.repo_name, args.docker_name, args.tag): 259 | print("yes") 260 | sys.exit(EXIT_OK) 261 | else: 262 | print("no") 263 | sys.exit(EXIT_RETURN_FALSE) 264 | 265 | 266 | def dockerfile_update(): 267 | # type: () -> None 268 | "Update the Dockerfile according to given tag" 269 | image = DockerImage(args.repo_name, args.docker_name, args.tag) 270 | image.dockerfile_update() 271 | 272 | 273 | def publish(): 274 | # type: () -> None 275 | """Publish docker image to docker hub, as well as git commit""" 276 | if DockerImage.has_tag(args.repo_name, args.docker_name, args.tag): 277 | logger.error("Tag %s already exists", args.tag) 278 | sys.exit(EXIT_FATAL_INVALID_ARGUMENTS) 279 | else: 280 | logging.info("docker tag to be publish: %s", args.tag) 281 | 282 | # Update Docker file 283 | image = DockerImage(args.repo_name, args.docker_name, args.tag) 284 | image.dockerfile_update() 285 | if subprocess.call([GitHelper.GIT_CMD, 'diff', '--exit-code']) != 0: # nosec 286 | subprocess.check_call([ # nosec 287 | GitHelper.GIT_CMD, 'commit', '-a', '-m', 288 | "[release] Image %s is released" % image.image_name]) 289 | 290 | # Building docker image 291 | logging.info("Building image %s", image.image_name) 292 | subprocess.check_call([ # nosec 293 | DockerImage.DOCKER_CMD, 'build', 294 | '-t', image.image_name, image.dockerfile_name]) 295 | 296 | # Tag and push docker image 297 | for current_tag in [image.final_tag, 'latest']: 298 | subprocess.check_call([ # nosec 299 | DockerImage.DOCKER_CMD, 'tag', image.image_name, 300 | "%s/%s/%s:%s" % ( 301 | args.registry, args.repo_name, 302 | args.docker_name, current_tag)]) 303 | subprocess.check_call([ # nosec 304 | DockerImage.DOCKER_CMD, 'push', 305 | "%s/%s/%s:%s" % ( 306 | args.registry, args.repo_name, 307 | args.docker_name, current_tag)]) 308 | 309 | # Git push to master if there is unpushed commits 310 | GitHelper.push('master') 311 | 312 | 313 | def parse(): 314 | # type () -> None 315 | """Parse options and arguments""" 316 | parser = argparse.ArgumentParser(description='Docker helper functions') 317 | parser.add_argument( 318 | '-r', '--repo-name', type=str, 319 | default='zanata', 320 | help='Docker Repository name. Default: zanata') 321 | parser.add_argument( 322 | '-R', '--registry', type=str, 323 | default='docker.io', 324 | help='Docker Registry name. Default: docker.io') 325 | 326 | subparsers = parser.add_subparsers( 327 | title='Command', description='Valid commands', 328 | help='Command help') 329 | has_tag_parser = subparsers.add_parser( 330 | 'has-tag', 331 | help='Whether the docker image has the given tag') 332 | has_tag_parser.add_argument( 333 | 'docker_name', type=str, 334 | help='Docker name, e.g. "server"') 335 | has_tag_parser.add_argument('tag', type=str, help='tag') 336 | has_tag_parser.set_defaults(func=has_tag) 337 | 338 | get_tags_parser = subparsers.add_parser( 339 | 'get-tags', 340 | help='Get all existing tags') 341 | get_tags_parser.add_argument( 342 | 'docker_name', type=str, 343 | help='Docker name, e.g. "server"') 344 | get_tags_parser.set_defaults(func=get_tags) 345 | 346 | dockerfile_update_parser = subparsers.add_parser( 347 | 'dockerfile-update', 348 | help='Update the Dockerfile according to tag') 349 | dockerfile_update_parser.add_argument( 350 | 'docker_name', type=str, 351 | help='Docker name, e.g. "server"') 352 | dockerfile_update_parser.add_argument( 353 | 'tag', type=str, 354 | help='tag to be publish') 355 | dockerfile_update_parser.set_defaults(func=dockerfile_update) 356 | 357 | publish_parser = subparsers.add_parser( 358 | 'publish', 359 | help='publish docker image according to the tag') 360 | publish_parser.add_argument( 361 | 'docker_name', type=str, 362 | help='Docker name, e.g. "server"') 363 | publish_parser.add_argument('tag', type=str, help='tag to be publish') 364 | publish_parser.set_defaults(func=publish) 365 | return parser.parse_args() 366 | 367 | if __name__ == '__main__': 368 | args = parse() 369 | args.func() 370 | -------------------------------------------------------------------------------- /zanata-server/conf/standalone.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 57 | 58 | 59 | 61 | 62 | 63 | 64 | 65 | 67 | 69 | 70 | 71 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 170 | 171 | 172 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | jdbc:mysql://${env.DB_HOSTNAME}:${env.DB_PORTNUMBER}/${env.DB_SCHEMA}?characterEncoding=UTF-8 192 | com.mysql.jdbc.Driver 193 | mysql-connector-java.jar 194 | 195 | 0 196 | 20 197 | FailingConnectionOnly 198 | 199 | 200 | ${env.DB_USERNAME} 201 | ${env.DB_PASSWORD} 202 | 203 | 204 | NOWARN 205 | 206 | 207 | true 208 | false 209 | 210 | 211 | 212 | 213 | 215 | jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 216 | h2 217 | 218 | sa 219 | sa 220 | 221 | 222 | 223 | 224 | org.h2.jdbcx.JdbcDataSource 225 | 226 | 227 | 228 | 229 | 230 | 233 | 234 | 235 | false 236 | 237 | 238 | 241 | 242 | 243 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 261 | 262 | 263 | 264 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 288 | 289 | 290 | 292 | 293 | 294 | 296 | 297 | 299 | 300 | 301 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 321 | 322 | 323 | 324 | 325 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 368 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 421 | 422 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 442 | 445 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 475 | 476 | 477 | 478 | 479 | 480 | 482 | 483 | 484 | 485 | 486 | 487 | 489 | 490 | 491 | 492 | 493 | 494 | 497 | 498 | 500 | 502 | 503 | 504 | 505 | 506 | 507 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 539 | 540 | 541 | 542 | 543 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 561 | 563 | 564 | 565 | 566 | ${jboss.bind.address:127.0.0.1} 567 | 568 | 569 | 571 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 594 | 596 | 598 | 600 | 602 | 604 | 606 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | --------------------------------------------------------------------------------