diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b1a6f7..95996e8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -85,36 +85,19 @@ jobs: if: contains(github.ref, 'refs/heads/master') && env.REGISTRY_USERNAME != '' run: DOCKER_TAG=centos7-jdk11 make push - latest: + centos8: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - name: Checkout uses: actions/checkout@v2 - - name: Build latest - run: make latest - - - name: Login to Docker - uses: docker/login-action@v1 - if: contains(github.ref, 'refs/heads/master') && env.REGISTRY_USERNAME != '' - with: - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Push latest - if: contains(github.ref, 'refs/heads/master') && env.REGISTRY_USERNAME != '' - run: DOCKER_TAG=latest make push - - latest-jdk8: - runs-on: ubuntu-latest - if: "!contains(github.event.head_commit.message, '[ci skip]')" - steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Build centos8 + run: make centos8 - - name: Build latest-jdk8 - run: make latest-jdk8 + - name: Test centos8 + if: "!contains(github.ref, 'refs/heads/master')" + run: ./scripts/test.sh centos8 refs/heads/4.15 "--distribution centos8" - name: Login to Docker uses: docker/login-action@v1 @@ -123,19 +106,19 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Push latest-jdk8 + - name: Push centos8 if: contains(github.ref, 'refs/heads/master') && env.REGISTRY_USERNAME != '' - run: DOCKER_TAG=latest-jdk8 make push + run: DOCKER_TAG=centos8 make push - latest-jdk11: + latest: runs-on: ubuntu-latest if: "!contains(github.event.head_commit.message, '[ci skip]')" steps: - name: Checkout uses: actions/checkout@v2 - - name: Build latest-jdk11 - run: make latest-jdk11 + - name: Build latest + run: make latest - name: Login to Docker uses: docker/login-action@v1 @@ -144,6 +127,6 @@ jobs: username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Push latest-jdk11 + - name: Push latest if: contains(github.ref, 'refs/heads/master') && env.REGISTRY_USERNAME != '' - run: DOCKER_TAG=latest-jdk11 make push + run: DOCKER_TAG=latest make push diff --git a/Makefile b/Makefile index cbace66..d260ea2 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ define build_tag endef .PHONY: all -all: centos6 centos7 centos7-jdk8 centos7-jdk11 latest latest-jdk8 latest-jdk11 +all: centos6 centos7 centos7-jdk8 centos7-jdk11 centos8 latest .PHONY: centos6 centos6: ## Build centos6 image @@ -54,20 +54,15 @@ centos7-jdk11: ## Build centos7-jdk11 image @ $(MAKE) --no-print-directory log-$@ $(call build_tag,centos7-jdk11,centos7,Dockerfile.jdk11) -.PHONY: latest -latest: ## Build latest image - @ $(MAKE) --no-print-directory log-$@ - $(call build_tag,latest,centos7,Dockerfile.jdk8) - -.PHONY: latest-jdk8 -latest-jdk8: ## Build latest-jdk8 image +.PHONY: centos8 +centos8: ## Build centos8 image @ $(MAKE) --no-print-directory log-$@ - $(call build_tag,latest-jdk8,centos7,Dockerfile.jdk8) + $(call build_tag,centos8,centos8,Dockerfile) -.PHONY: latest-jdk11 -latest-jdk11: ## Build latest-jdk11 image +.PHONY: latest +latest: ## Build latest image @ $(MAKE) --no-print-directory log-$@ - $(call build_tag,latest-jdk11,centos7,Dockerfile.jdk11) + $(call build_tag,latest,centos8,Dockerfile) .PHONY: push push: DOCKER_TAG ?= diff --git a/README.md b/README.md index db23a7e..73d64db 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,9 @@ project. ## Supported tags and respective `Dockerfile` links -- [`latest`, `latest-jdk8`, `centos7`, `centos7-jdk8`(centos7/Dockerfile.jdk8)][centos7-dockerfile] -- [`latest-jdk11`, `centos7-jdk11` (centos7/Dockerfile.jdk11)][latest-jdk11-dockerfile] +- [`latest`, `centos8` (centos8/Dockerfile)][centos8-dockerfile] +- [`centos7`, `centos7-jdk8`(centos7/Dockerfile.jdk8)][centos7-jdk8-dockerfile] +- [`centos7-jdk11` (centos7/Dockerfile.jdk11)][centos7-jdk11-dockerfile] - [`centos6` (centos6/Dockerfile)][centos6-dockerfile] [EOL - not supported anymore] ## Packages installed in container @@ -62,10 +63,10 @@ Let's assume we want to build packages for CentOS 7 on CentOS 7. We pull that image first: ```bash -docker pull khos2ow/cloudstack-rpm-builder:centos7-jdk11 +docker pull khos2ow/cloudstack-rpm-builder:centos8 ``` -You can replace `centos7-jdk11` tag by [one of the other tags]. +You can replace `centos8` tag by [one of the other tags]. ### Build local repository @@ -92,7 +93,7 @@ always expects the `cloudstack` code exists in `/mnt/build` path.) ```bash docker run \ -v /tmp:/mnt/build \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 --distribution centos7 [ARGS...] + khos2ow/cloudstack-rpm-builder:centos8 --distribution centos7 [ARGS...] ``` Or if your local cloudstack folder has other name, you need to map it to @@ -101,7 +102,7 @@ Or if your local cloudstack folder has other name, you need to map it to ```bash docker run \ -v /tmp/cloudstack-custom-name:/mnt/build/cloudstack \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 --distribution centos7 [ARGS...] + khos2ow/cloudstack-rpm-builder:centos8 --distribution centos7 [ARGS...] ``` After the build has finished the `.rpm` packages are available in @@ -125,10 +126,10 @@ flag) in `/mnt/build/cloudstack` inside the container and can be accessed from ```bash docker run \ -v /tmp:/mnt/build \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 \ + khos2ow/cloudstack-rpm-builder:centos8 \ --git-remote https://github.com/apache/cloudstack.git \ --git-ref master \ - --distribution centos7 [ARGS...] + --distribution centos8 [ARGS...] ``` Note that any valid git Refspec is acceptable, such as: @@ -155,7 +156,7 @@ it run faster. docker run \ -v /tmp:/mnt/build \ -v ~/.m2:/root/.m2 \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 --distribution centos7 [ARGS...] + khos2ow/cloudstack-rpm-builder:centos8 --distribution centos7 [ARGS...] ``` ### Adjust host owner permission @@ -175,7 +176,7 @@ docker run \ -v /tmp:/mnt/build \ -e "USER_ID=$(id -u)" \ -e "USER_GID=$(id -g)" \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 --distribution centos7 [ARGS...] + khos2ow/cloudstack-rpm-builder:centos8 --distribution centos7 [ARGS...] ``` ## Builder help @@ -185,7 +186,7 @@ To see all the available options you can pass to `docker run ...` command: ```bash docker run \ -v /tmp:/mnt/build \ - khos2ow/cloudstack-rpm-builder:centos7-jdk11 --help + khos2ow/cloudstack-rpm-builder:centos8 --help ``` ## License @@ -193,8 +194,9 @@ docker run \ Licensed under [Apache License version 2.0]. Please see the [LICENSE] file included in the root directory of the source tree for extended license details. -[centos7-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos7/Dockerfile.jdk8 -[latest-jdk11-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos7/Dockerfile.jdk11 +[centos8-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos8/Dockerfile +[centos7-jdk8-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos7/Dockerfile.jdk8 +[centos7-jdk11-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos7/Dockerfile.jdk11 [centos6-dockerfile]: https://github.com/khos2ow/cloudstack-rpm-builder/blob/master/centos6/Dockerfile [one of the other tags]: #supported-tags-and-respective-dockerfile-links [https://github.com/apache/cloudstack]: https://github.com/apache/cloudstack diff --git a/centos8/Dockerfile b/centos8/Dockerfile new file mode 100644 index 0000000..40fe2fd --- /dev/null +++ b/centos8/Dockerfile @@ -0,0 +1,63 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +FROM centos:8 +LABEL maintainer="Khosrow Moossavi (@khos2ow)" + +RUN \ + yum clean metadata && \ + yum install -y epel-release && \ + yum clean metadata && \ + yum install -y \ + make \ + which \ + mlocate \ + tar \ + rpm-build \ + yum-utils \ + createrepo \ + mkisofs \ + git \ + java-11-openjdk-devel \ + tomcat \ + python python3 python-dev py-pip \ + python-argparse python-yaml python-pip python-wheel \ + mysql-connector-python \ + gcc \ + gcc-c++ \ + jq \ + wget \ + ws-commons-util && \ + yum upgrade python-setuptools && \ + pip install --upgrade pip && \ + wget http://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo && \ + yum clean metadata && \ + yum install -y \ + apache-maven && \ + yum clean all && rm -rf /var/cache/yum && \ + sed -i "s/%dist .el7$/%dist .el7.centos/g" /etc/rpm/macros.dist + +ENV JAVA_HOME=/usr/lib/jvm/java-11 +RUN alternatives --set java $(readlink -f ${JAVA_HOME}/bin/java) + +VOLUME /mnt/build +WORKDIR /mnt/build + +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh +COPY environment-info.sh /usr/local/bin/environment-info.sh + +ENTRYPOINT ["docker-entrypoint.sh"] diff --git a/centos8/docker-entrypoint.sh b/centos8/docker-entrypoint.sh new file mode 100755 index 0000000..8f5cf88 --- /dev/null +++ b/centos8/docker-entrypoint.sh @@ -0,0 +1,251 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -e + +# Flag to show help text +show_help=false + +# Workspace path +workspace_path="" + +# Using remote git repository variables +use_remote=false +git_remote="" +git_ref="" +remove_first=false + +# packaging flags to be sent to script +PKG_ARGS="" +HELP_ARG="" + +while [ -n "$1" ]; do + case "$1" in + --git-remote) + if [ -n "$git_remote" ]; then + echo "Error: you have already entered value for --git-remote" + exit 1 + else + git_remote=$2 + use_remote=true + shift 2 + fi + ;; + + --git-ref) + if [ -n "$git_ref" ]; then + echo "Error: you have already entered value for --git-ref" + exit 1 + else + git_ref=$2 + use_remote=true + shift 2 + fi + ;; + + --remove-first) + if [ $remove_first = true ]; then + echo "Error: you have already entered --remove_first" + exit 1 + else + remove_first=true + shift 1 + fi + ;; + + --workspace-path) + if [ -n "$workspace_path" ]; then + echo "Error: you have already entered value for --workspace-path" + exit 1 + else + workspace_path=$2 + shift 2 + fi + ;; + + -h | --help) + if [ $show_help = true ]; then + echo "Error: you have already entered -h, --help" + exit 1 + else + show_help=true + HELP_ARG="$1" + shift 1 + fi + ;; + + -* | --* | *) + PKG_ARGS="$PKG_ARGS $1" + shift 1 + ;; + esac +done + +set -- $PKG_ARGS + +# use '/mnt/build/cloudstack' as default workspace path +if [ -z "$workspace_path" ]; then + workspace_path="/mnt/build/cloudstack" +fi + +# Both of --git-remote AND --git-ref must be specified at the same time +if [ $use_remote = true ]; then + if [ -z "$git_remote" -o -z "$git_ref" ]; then + echo "Error: you must specify --git-remote and --git-ref at the same time" + exit 1 + fi +fi + +# Check if cloudstack directory exists or not. Options are either: +# +# 1) cloudstack directory is provided through the host's volume +# 2) cloudstack directory is NOT provided and git remote and ref are provided +# +# Any combination of the above situations is invalid. +if [ -d "${workspace_path}" ]; then + if [ $use_remote = true ]; then + if [ $remove_first = false ]; then + echo "Error: Could not clone remote git repository, '${workspace_path}' exists" + exit 1 + else + echo -e "\e[0;32mremoving ${workspace_path} ...\e[0m" + rm -rf ${workspace_path} + echo "" + fi + fi +else + if [ $use_remote = false ]; then + echo "Could not find '${workspace_path}'" + exit 1 + fi +fi + +# Print out some environment information +environment-info.sh + +# Clone the remote provided git repo and ref +if [ $use_remote = true ]; then + echo -e "\e[0;32mcloning $git_remote ...\e[0m" + git clone --quiet --depth=50 $git_remote ${workspace_path} + echo "" + + cd ${workspace_path} + + echo -e "\e[0;32mfetching $git_ref ...\e[0m" + git fetch --quiet origin +$git_ref: + echo "" + + echo -e "\e[0;32mchecking out $git_ref ...\e[0m" + git checkout --quiet --force FETCH_HEAD + echo "" +fi + +# Make sure package.sh script exists before going any further +if [ ! -f "${workspace_path}/packaging/package.sh" ]; then + echo "Could not find '${workspace_path}/packaging/package.sh'" + exit 1 +fi + +# convert LONG flags to SHORT flags for anything prior 4.12.x.x +echo -e "\e[0;32mdetecting CloudStack version ...\e[0m" +pom_version=$(cd ${workspace_path}; mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec) +echo "${pom_version}" +major_version=$(echo ${pom_version} | cut -d. -f1) +minor_version=$(echo ${pom_version} | cut -d. -f2) +echo "" + +if [ $major_version -lt 4 ] || [ $major_version -eq 4 -a $minor_version -lt 12 ]; then + PKG_ARGS="" + + for arg in "$@"; do + if [ -n "$arg" ]; then + case "$arg" in + --distribution) PKG_ARGS="$PKG_ARGS -d" ;; + --pack) PKG_ARGS="$PKG_ARGS -p" ;; + --release) PKG_ARGS="$PKG_ARGS -r" ;; + --simulator) PKG_ARGS="$PKG_ARGS -s" ;; + -* | *) PKG_ARGS="$PKG_ARGS $arg" ;; + esac + fi + done + + set -- $PKG_ARGS + + if [ "$HELP_ARG" == "--help" ]; then + HELP_ARG="-h" + fi +fi + +# Show help, both from docker-entrypoint.sh and ${workspace_path}/packaging/package.sh +if [ $show_help = true ]; then + help=$(cd ${workspace_path}/packaging; bash -x ./package.sh $HELP_ARG) + cat << USAGE +Usage: docker run ... khos2ow/cloudstack-rpm-builder [DOCKER_OPTIONS] ... [PACKAGING_OPTIONS]... +CloudStack RPM builder which acts as a wrapper for CloudStack package script. Optionally +you can specify remote git repository and ref to be cloned and checked out and run the +packaging script on in. + +Optional arguments: + --git-remote string Set the git remote repository to clone (must be set together with \`--git-ref\`) (default: none) + --git-ref string Set the ref from remote repository to check out (must be set together with \`--git-remote\`) (default: none) + --remove-first Remove existing \`${workspace_path}\` directory before cloning (default: false) + --workspace-path string Set the directory path of workspace to work with (default: \`/mnt/build/cloudstack\`) + +Other arguments: + -h, --help Display this help message and exit + +Examples: + docker run ... khos2ow/cloudstack-rpm-builder [PACKAGING_OPTIONS] ... + docker run ... khos2ow/cloudstack-rpm-builder --git-remote https://path.to.repo/cloudstack.git --git-ref foo-branch [PACKAGING_OPTIONS] ... + +-------- + +$help + +USAGE + exit 0 +fi + +# Adjust user and group provided by host +function adjust_owner() { + # if both set then change the owner + if [ -n "${USER_ID}" -a -z "${USER_GID}" ]; then + chown -R ${USER_ID} ${workspace_path} + elif [ -n "${USER_ID}" -a -n "${USER_GID}" ]; then + chown -R ${USER_ID}:${USER_GID} ${workspace_path} + fi +} + +{ + cd ${workspace_path}/packaging + + echo -e "\e[0;32mpackaging CloudStack RPM packages ...\e[0m" + + # do the packaging + bash -x ./package.sh $@ && { + # create RPMs + createrepo ${workspace_path}/dist/rpmbuild/RPMS + adjust_owner + } +} || { + status=$? + + adjust_owner + echo "Packaging RPM failed" + exit $status +} diff --git a/centos8/environment-info.sh b/centos8/environment-info.sh new file mode 100755 index 0000000..0d7ed64 --- /dev/null +++ b/centos8/environment-info.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set -e + +EXTRA_LINE="" + +print_title() { + local version_label="" + if [[ "$1" = *":" ]]; then + version_label="" + else + version_label=" version:" + fi + echo -e "${EXTRA_LINE}\e[1;34m$1${version_label}\e[0m" +} + +print_title "system information:" +cat /etc/*-release + +EXTRA_LINE="\n" + +print_title "git" +git --version + +print_title "java" +java -version + +print_title "tomcat" +tomcat version + +print_title "maven" +mvn --version + +print_title "python" +python --version + +print_title "python3" +python3 --version + +print_title "createrepo" +createrepo --version + +print_title "rpmbuild" +rpmbuild --version + +print_title "genisoimage" +genisoimage --version + +echo ""