diff --git a/README.adoc b/README.adoc index 2b6be244b..bced39ec8 100644 --- a/README.adoc +++ b/README.adoc @@ -71,3 +71,4 @@ Please refer to the link:CONTRIBUTING.adoc[] for more details. == License https://www.apache.org/licenses/LICENSE-2.0[Apache License v2.0] + diff --git a/ci/images/ci-image/Dockerfile b/ci/images/ci-image/Dockerfile new file mode 100644 index 000000000..7363fb1a2 --- /dev/null +++ b/ci/images/ci-image/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:focal-20220801 +# +#VOLUME /var/run/docker.sock +# +########################################################### +# JAVA +########################################################### + +ADD ./setup.sh /setup.sh +ADD ./get-jdk-url.sh /get-jdk-url.sh +ADD ./get-docker-url.sh /get-docker-url.sh +RUN ./setup.sh java17 + +ENV JAVA_HOME /opt/openjdk +ENV PATH $PATH:$JAVA_HOME/bin +ENV MAVEN_HOME /usr/share/maven +ENV MAVEN_CONFIG "$USER_HOME_DIR/.m2" + +# + + + +#ENTRYPOINT ["/usr/local/bin/dockerd-entrypoint.sh"] +#ENTRYPOINT ["sh"] +ENTRYPOINT [ "switch", "shell=/bin/bash", "--", "codep", "/bin/docker daemon" ] \ No newline at end of file diff --git a/ci/images/ci-image/entrypoint.sh b/ci/images/ci-image/entrypoint.sh new file mode 100755 index 000000000..f5561316e --- /dev/null +++ b/ci/images/ci-image/entrypoint.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# +# Copyright 2021 - 2022 the original author or authors. +# +# Licensed 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 +# +# https://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 + +mvn --version + +exec "$@" \ No newline at end of file diff --git a/ci/images/ci-image/get-docker-url.sh b/ci/images/ci-image/get-docker-url.sh new file mode 100755 index 000000000..644259086 --- /dev/null +++ b/ci/images/ci-image/get-docker-url.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Copyright 2021 - 2022 the original author or authors. +# +# Licensed 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 +# +# https://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 + +version="20.10.17" +echo "https://download.docker.com/linux/static/stable/x86_64/docker-$version.tgz"; \ No newline at end of file diff --git a/ci/images/ci-image/get-jdk-url.sh b/ci/images/ci-image/get-jdk-url.sh new file mode 100755 index 000000000..95a546237 --- /dev/null +++ b/ci/images/ci-image/get-jdk-url.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -e + +case "$1" in + java17) + echo "https://github.com/bell-sw/Liberica/releases/download/17.0.4+8/bellsoft-jdk17.0.4+8-linux-amd64.tar.gz" +# echo "https://github.com/bell-sw/Liberica/releases/download/17.0.4+8/bellsoft-jdk17.0.4+8-linux-aarch64.tar.gz" + + ;; + java18) + echo "https://github.com/bell-sw/Liberica/releases/download/18.0.2+10/bellsoft-jdk18.0.2+10-linux-amd64.tar.gz" + ;; + *) + echo $"Unknown java version" + exit 1 +esac \ No newline at end of file diff --git a/ci/images/ci-image/setup.sh b/ci/images/ci-image/setup.sh new file mode 100755 index 000000000..7b392090b --- /dev/null +++ b/ci/images/ci-image/setup.sh @@ -0,0 +1,106 @@ +#!/bin/bash +set -ex + +########################################################### +# UTILS +########################################################### + +export DEBIAN_FRONTEND=noninteractive +apt-get update +apt-get install --no-install-recommends -y git curl jq tzdata ca-certificates net-tools libxml2-utils git curl libudev1 libxml2-utils iptables iproute2 jq gnupg lsb-release software-properties-common python3-pip +apt-get update +ln -fs /usr/share/zoneinfo/UTC /etc/localtime +dpkg-reconfigure --frontend noninteractive tzdata +rm -rf /var/lib/apt/lists/* + +# curl https://raw.githubusercontent.com/spring-io/concourse-java-scripts/v0.0.4/concourse-java.sh > /opt/concourse-java.sh + + +########################################################### +# JAVA +########################################################### +JDK_URL=$( ./get-jdk-url.sh $1 ) + +mkdir -p /opt/openjdk +cd /opt/openjdk +curl -L ${JDK_URL} | tar zx --strip-components=1 +test -f /opt/openjdk/bin/java +test -f /opt/openjdk/bin/javac + +if [[ $# -eq 2 ]]; then + cd / + TOOLCHAIN_JDK_URL=$( ./get-jdk-url.sh $2 ) + + mkdir -p /opt/openjdk-toolchain + cd /opt/openjdk-toolchain + curl -L ${TOOLCHAIN_JDK_URL} | tar zx --strip-components=1 + test -f /opt/openjdk-toolchain/bin/java + test -f /opt/openjdk-toolchain/bin/javac +fi + +############################################################ +## MAVEN +############################################################ + +#INSTALL MAVEN +MAVEN_VERSION=3.6.3 + +# 2- Define a constant with the working directory +USER_HOME_DIR="/root" + +# 4- Define the URL where maven can be downloaded from +BASE_URL=https://apache.osuosl.org/maven/maven-3/${MAVEN_VERSION}/binaries + +# 5- Create the directories, download maven, validate the download, install it, remove downloaded file and set links +mkdir -p /usr/share/maven /usr/share/maven/ref \ + && echo "Downlaoding maven" \ + && curl -fsSL -o /tmp/apache-maven.tar.gz ${BASE_URL}/apache-maven-${MAVEN_VERSION}-bin.tar.gz \ + \ + && echo "Unziping maven" \ + && tar -xzf /tmp/apache-maven.tar.gz -C /usr/share/maven --strip-components=1 \ + \ + && echo "Cleaning and setting links" \ + && rm -f /tmp/apache-maven.tar.gz \ + && ln -s /usr/share/maven/bin/mvn /usr/bin/mvn + +# 6- Define environmental variables required by Maven, like Maven_Home directory and where the maven repo is located + + +########################################################### +# DOCKER +########################################################### +#mkdir -p /etc/apt/keyrings +#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +#echo \ +# "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ +# $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +#sudo apt-get update +#sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin +# +# +#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - +#APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 +#apt-key fingerprint 0EBFCD88 +#add-apt-repository "deb [arch=arm64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" +#apt-get update +#apt-cache policy docker-ce +#apt-get -y install docker-ce +#usermod -aG docker root + + +###### + +cd / +DOCKER_URL=$( ./get-docker-url.sh ) +curl -L ${DOCKER_URL} | tar zx +mv /docker/* /bin/ +chmod +x /bin/docker* + +export ENTRYKIT_VERSION=0.4.0 +curl -L https://github.com/progrium/entrykit/releases/download/v${ENTRYKIT_VERSION}/entrykit_${ENTRYKIT_VERSION}_Linux_x86_64.tgz | tar zx +chmod +x entrykit && \ +mv entrykit /bin/entrykit && \ +entrykit --symlink + +# Docker Compose +pip3 install docker-compose \ No newline at end of file diff --git a/ci/pipeline.yml b/ci/pipeline.yml new file mode 100644 index 000000000..b2c68bf8c --- /dev/null +++ b/ci/pipeline.yml @@ -0,0 +1,187 @@ +--- +anchors: + git-repo-resource-source: &git-repo-resource-source + uri: ((github-repo-uri)) # https://github.com/spring-projects-experimental/spring-boot-migrator + username: ((github-repo-user)) # fabapp2 + password: ((github-ci-release-token)) + branch: ((branch)) + registry-image-resource-source: ®istry-image-resource-source + username: ((docker-hub-username)) + password: ((docker-hub-password)) + tag: ((milestone)) + registry_mirror: + host: ((docker-hub-mirror)) + username: ((docker-hub-mirror-username)) + password: ((docker-hub-mirror-password)) + docker-hub-mirror-vars: &docker-hub-mirror-vars + docker-hub-mirror: ((docker-hub-mirror)) + docker-hub-mirror-username: ((docker-hub-mirror-username)) + docker-hub-mirror-password: ((docker-hub-mirror-password)) + +resource_types: + - name: registry-image + type: registry-image + source: + repository: concourse/registry-image-resource + tag: 1.5.0 + - name: git-pull-request + type: docker-image + source: + repository: ((github-repo-name)) + - name: pull-request + type: registry-image + source: + repository: teliaoss/github-pr-resource + tag: v0.23.0 + + +resources: +# The ci dir in the repo, used to trigger an image build on change + - name: ci-images-git-repo + type: git + icon: github + source: + uri: ((github-repo-uri)) + branch: ((branch)) + paths: ["ci/images/*"] +# The git repo + - name: git-repo + type: git + icon: github + source: + <<: *git-repo-resource-source +# The image used to run the build + - name: ci-image + type: registry-image + icon: docker + source: + <<: *registry-image-resource-source + repository: fkrueger096/spring-boot-migrator-ci + tag: latest +# branches for multi-branch pipeline +# - name: branches +# type: git-branches +# source: +# uri: ((github-repo-uri)) +# branch_regex: '.*' + + +# git PR + - name: git-pull-request + type: pull-request + icon: source-pull + source: + access_token: ((github-ci-pull-request-token)) + repository: ((github-repo-name)) + base_branch: main + ignore_paths: [ "ci/*" ] + +image_resource: + type: registry-image + source: + repository: concourse/oci-build-task + tag: 0.10.0 + registry_mirror: + host: ((docker-hub-mirror)) + username: ((docker-hub-mirror-username)) + password: ((docker-hub-mirror-password)) + +jobs: +# Build and push CI image when ci-images-git-repo changed + - name: build-ci-images + plan: + - get: ci-images-git-repo + trigger: true + - get: git-repo + - in_parallel: + - task: build-ci-image + privileged: true + file: git-repo/ci/tasks/build-ci-image.yml + output_mapping: + image: ci-image + vars: + ci-image-name: ci-image + <<: *docker-hub-mirror-vars + - in_parallel: + - put: ci-image + params: + image: ci-image/image.tar + +# Build application + - name: build + public: true + plan: + - in_parallel: + - get: ci-image + - get: git-repo + trigger: true + - task: compile + image: ci-image + file: git-repo/ci/tasks/maven-build.yml +# - in_parallel: +# fail_fast: true +# steps: +# - task: run-unit-tests +# image: ci-image +# file: git-repo/ci/tasks/maven-unit-test.yml +# - task: run-integration-tests +# image: ci-image +# file: git-repo/ci/tasks/maven-integration-test.yml + +# - name: set-feature-pipelines +# plan: +# - in_parallel: +# - get: feature-branches +# trigger: true +# - get: git-repo +# - load_var: branches +# file: feature-branches/branches.json +# - across: +# - var: branch +# values: ((.:branches)) +# set_pipeline: dev +# file: examples/pipelines/multi-branch/template.yml +# instance_vars: {feature: ((.:branch.groups.feature))} +# vars: {branch: ((.:branch.name))} + +# Build every new PR + - name: build-pull-requests + serial: true + public: true + plan: + - get: ci-image + - get: git-repo + resource: git-pull-request + trigger: true + version: every + - do: + - put: git-pull-request + params: + path: git-repo + status: pending + - task: build-project + image: ci-image + file: git-repo/ci/tasks/build-pr-project.yml +# timeout: 30m # ((task-timeout)) + on_success: + put: git-pull-request + params: + path: git-repo + status: success + on_failure: + put: git-pull-request + params: + path: git-repo + status: failure + +groups: + - name: "builds" + jobs: ["build"] +# - name: "releases" +# jobs: ["stage-milestone", "stage-rc", "stage-release", "promote-milestone", "promote-rc", "promote-release", "create-github-release", "publish-gradle-plugin", "publish-to-sdkman", "update-homebrew-tap"] +# - name: "system-tests" +# jobs: ["run-system-tests", "jdk18-run-system-tests"] + - name: "ci-images" + jobs: ["build-ci-images"] + - name: "pull-requests" + jobs: ["build-pull-requests"] \ No newline at end of file diff --git a/ci/scripts/build-pr-project.sh b/ci/scripts/build-pr-project.sh new file mode 100755 index 000000000..ea5ee2139 --- /dev/null +++ b/ci/scripts/build-pr-project.sh @@ -0,0 +1,22 @@ +#!/bin/bash +# +# Copyright 2021 - 2022 the original author or authors. +# +# Licensed 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 +# +# https://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 + +pushd git-repo > /dev/null +mvn clean install +popd > /dev/null \ No newline at end of file diff --git a/ci/tasks/build-ci-image.yml b/ci/tasks/build-ci-image.yml new file mode 100644 index 000000000..bb64df8ed --- /dev/null +++ b/ci/tasks/build-ci-image.yml @@ -0,0 +1,34 @@ +--- +platform: linux +image_resource: + type: registry-image + source: + repository: concourse/oci-build-task + tag: 0.10.0 + registry_mirror: + host: ((docker-hub-mirror)) + username: ((docker-hub-mirror-username)) + password: ((docker-hub-mirror-password)) +inputs: + - name: ci-images-git-repo + - name: git-repo +# - name: docker-image +outputs: + - name: image +caches: + - path: ci-image-cache +params: + CONTEXT: git-repo/ci/images/ci-image + DOCKERFILE: git-repo/ci/images/ci-image/Dockerfile + DOCKER_HUB_AUTH: ((docker-hub-auth)) + REGISTRY_MIRRORS: ((docker-hub-mirror)) +run: + path: /bin/sh + args: + - "-c" + - | + mkdir -p /root/.docker + cat > /root/.docker/config.json < - - rewrite-snapshots - rewrite-snapshots - https://oss.sonatype.org/content/repositories/snapshots/ - + + + + + jcenter jcenter