Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the build.sh script to work with podman #559

Merged
merged 14 commits into from
Dec 11, 2023
Merged
10 changes: 5 additions & 5 deletions .github/workflows/build-pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ jobs:
cache: 'maven'
- name: Login to docker.io
if: github.event_name == 'pull_request'
uses: docker/login-action@v2
uses: redhat-actions/podman-login@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
registry: docker.io
- name: Login to quay.io
if: github.event_name == 'pull_request'
uses: docker/login-action@v2
uses: redhat-actions/podman-login@v1
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
- name: Build with Maven
run: mvn -B clean install -U -Pintegration
- name: Build docker images
- name: Build images
if: github.event_name == 'pull_request'
run: ./build/build.sh --tag:${{ env.PR_IMAGE_TAG }}
- name: Push docker images
- name: Push images
if: github.event_name == 'pull_request'
run: docker push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }}
run: podman push quay.io/eclipse/che-server:${{ env.PR_IMAGE_TAG }}
10 changes: 5 additions & 5 deletions .github/workflows/next-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ jobs:
java-version: '11'
cache: 'maven'
- name: Login to docker.io
uses: docker/login-action@v2
uses: redhat-actions/podman-login@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
registry: docker.io
- name: Login to quay.io
uses: docker/login-action@v2
uses: redhat-actions/podman-login@v1
with:
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
- name: Build with Maven
run: mvn -B clean install -U -Pintegration
- name: Build docker images
- name: Build images
id: build
run: |
echo "short_sha1=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
./build/build.sh --tag:next --sha-tag
- name: Push docker images
run: |
docker push quay.io/eclipse/che-server:next
docker push quay.io/eclipse/che-server:${{ steps.build.outputs.short_sha1 }}
podman push quay.io/eclipse/che-server:next
podman push quay.io/eclipse/che-server:${{ steps.build.outputs.short_sha1 }}
- name: Create failure MM message
if: ${{ failure() }}
run: |
Expand Down
65 changes: 36 additions & 29 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ IMAGE_ALIASES=${IMAGE_ALIASES:-}
ERROR=${ERROR:-}
DIR=${DIR:-}
SHA_TAG=${SHA_TAG:-}
BUILDER=${BUILDER:-}

skip_tests() {
if [ $SKIP_TESTS = "true" ]; then
Expand Down Expand Up @@ -49,6 +50,7 @@ init() {
ARGS=""
OPTIONS=""
DOCKERFILE=""
BUILD_COMMAND="build"
BUILD_ARGS=""

while [ $# -gt 0 ]; do
Expand Down Expand Up @@ -104,6 +106,37 @@ build() {
DIR=$(cd "$(dirname "$0")"; pwd)
fi

BUILD_COMAMAND="build"
if [ -z $BUILDER ]; then
echo "BUILDER is not specified, trying with podman"
BUILDER=$(command -v podman || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] podman is not installed, trying with buildah"
BUILDER=$(command -v buildah || true)
if [[ ! -x $BUILDER ]]; then
echo "[WARNING] buildah is not installed, trying with docker"
BUILDER=$(command -v docker || true)
if [[ ! -x $BUILDER ]]; then
echo "[ERROR] This script requires podman, buildah or docker to be installed. Must abort!"; exit 1
fi
else
BUILD_COMMAND="bud"
fi
fi
else
if [[ ! -x $(command -v "$BUILDER" || true) ]]; then
echo "Builder $BUILDER is missing. Aborting."; exit 1
fi
if [[ $BUILDER =~ "docker" || $BUILDER =~ "podman" ]]; then
if [[ ! $($BUILDER ps) ]]; then
echo "Builder $BUILDER is not functioning. Aborting."; exit 1
fi
fi
if [[ $BUILDER =~ "buildah" ]]; then
BUILD_COMMAND="bud"
fi
fi

# If Dockerfile is empty, build all Dockerfiles
if [ -z ${DOCKERFILE} ]; then
DOCKERFILES_TO_BUILD="$(ls ${DIR}/Dockerfile*)"
Expand Down Expand Up @@ -138,14 +171,14 @@ build_image() {
-e "s;\${BUILD_PREFIX};${PREFIX};" \
-e "s;\${BUILD_TAG};${TAG};" \
> ${DIR}/.Dockerfile
cd "${DIR}" && docker build -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} .
cd "${DIR}" && "${BUILDER}" "${BUILD_COMMAND}" -f ${DIR}/.Dockerfile -t ${IMAGE_NAME} ${BUILD_ARGS} .
DOCKER_BUILD_STATUS=$?
rm ${DIR}/.Dockerfile
if [ $DOCKER_BUILD_STATUS -eq 0 ]; then
printf "Build of ${BLUE}${IMAGE_NAME} ${GREEN}[OK]${NC}\n"
if [ ! -z "${SHA_TAG}" ]; then
SHA_IMAGE_NAME=${ORGANIZATION}/${PREFIX}-${NAME}:${SHA_TAG}
docker tag ${IMAGE_NAME} ${SHA_IMAGE_NAME}
"${BUILDER}" tag ${IMAGE_NAME} ${SHA_IMAGE_NAME}
DOCKER_TAG_STATUS=$?
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
printf "Re-tagging with SHA based tag ${BLUE}${SHA_IMAGE_NAME} ${GREEN}[OK]${NC}\n"
Expand All @@ -157,7 +190,7 @@ build_image() {
if [ ! -z "${IMAGE_ALIASES}" ]; then
for TMP_IMAGE_NAME in ${IMAGE_ALIASES}
do
docker tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
"${BUILDER}" tag ${IMAGE_NAME} ${TMP_IMAGE_NAME}:${TAG}
DOCKER_TAG_STATUS=$?
if [ $DOCKER_TAG_STATUS -eq 0 ]; then
printf " /alias ${BLUE}${TMP_IMAGE_NAME}:${TAG}${NC} ${GREEN}[OK]${NC}\n"
Expand All @@ -175,32 +208,6 @@ build_image() {
fi
}

check_docker() {
if ! docker ps > /dev/null 2>&1; then
output=$(docker ps)
printf "${RED}Docker not installed properly: ${output}${NC}\n"
exit 1
fi
}

docker_exec() {
if has_docker_for_windows_client; then
MSYS_NO_PATHCONV=1 docker.exe "$@"
else
"$(which docker)" "$@"
fi
}

has_docker_for_windows_client() {
GLOBAL_HOST_ARCH=$(docker version --format {{.Client}})

if [[ "${GLOBAL_HOST_ARCH}" = *"windows"* ]]; then
return 0
else
return 1
fi
}

get_full_path() {
echo "$(cd "$(dirname "${1}")"; pwd)/$(basename "$1")"
}
Expand Down
16 changes: 13 additions & 3 deletions devfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,23 @@ components:
- name: m2
volume: {}
commands:
- id: build
- id: buildsources
exec:
label: "1. Build"
label: "1. Build sources"
component: tools
workingDir: ${PROJECT_SOURCE}
commandLine: |
mvn clean install -DskipTests
mvn clean install -V -e -Pfast -DskipTests -Dskip-validate-sources -Denforcer.skip=true
group:
kind: build
isDefault: true
- id: buildimage
exec:
label: "2. Build image"
component: tools
workingDir: ${PROJECT_SOURCE}
commandLine: |
./build/build.sh
group:
kind: build
isDefault: true