Skip to content

Commit

Permalink
Modify the build.sh script to work with podman
Browse files Browse the repository at this point in the history
  • Loading branch information
vinokurig committed Sep 18, 2023
1 parent a3cceea commit 1e91107
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 47 deletions.
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: ./dockerfiles/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 }}
22 changes: 11 additions & 11 deletions .github/workflows/next-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,37 @@ 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
./dockerfiles/build.sh --tag:next --sha-tag
- name: Push docker images
run: |
docker push quay.io/eclipse/che-endpoint-watcher:next
docker push quay.io/eclipse/che-endpoint-watcher:${{ steps.build.outputs.short_sha1 }}
podman push quay.io/eclipse/che-endpoint-watcher:next
podman push quay.io/eclipse/che-endpoint-watcher:${{ steps.build.outputs.short_sha1 }}
docker push quay.io/eclipse/che-keycloak:next
docker push quay.io/eclipse/che-keycloak:${{ steps.build.outputs.short_sha1 }}
podman push quay.io/eclipse/che-keycloak:next
podman push quay.io/eclipse/che-keycloak:${{ steps.build.outputs.short_sha1 }}
docker push quay.io/eclipse/che-postgres:next
docker push quay.io/eclipse/che-postgres:${{ steps.build.outputs.short_sha1 }}
podman push quay.io/eclipse/che-postgres:next
podman push quay.io/eclipse/che-postgres:${{ steps.build.outputs.short_sha1 }}
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
63 changes: 34 additions & 29 deletions dockerfiles/build.include
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,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 @@ -103,6 +104,36 @@ build() {
DIR=$(cd "$(dirname "$0")"; pwd)
fi

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] neither docker, buildah, nor podman are installed. Aborting"; 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 @@ -137,14 +168,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 -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 @@ -156,7 +187,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 @@ -174,32 +205,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
4 changes: 2 additions & 2 deletions dockerfiles/postgres/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# SPDX-License-Identifier: EPL-2.0
#

FROM centos/postgresql-96-centos7
FROM docker.io/centos/postgresql-96-centos7
ADD init-che-user-and-run.sh.erb init-che-user.sh.erb /var/lib/pgsql/
RUN cat /var/lib/pgsql/init-che-user.sh.erb | \
sed -e "/exit 0/d" > /var/lib/pgsql/init-che-user-and-run.sh && \
Expand All @@ -16,5 +16,5 @@ RUN chmod +x /var/lib/pgsql/init-che-user-and-run.sh
USER postgres
ADD --chown=postgres postgresql.conf.debug /opt/app-root/src/postgresql-cfg/
ADD init-debug.sh /opt/app-root/src/postgresql-pre-start/
RUN chgrp -R 0 /opt/app-root/src/postgresql-cfg/ && chmod -R g+rwX /opt/app-root/src/postgresql-cfg/
# RUN chgrp -R 0 /opt/app-root/src/postgresql-cfg/ && chmod -R g+rwX /opt/app-root/src/postgresql-cfg/
CMD ["/var/lib/pgsql/init-che-user-and-run.sh"]

0 comments on commit 1e91107

Please sign in to comment.