Skip to content

Commit

Permalink
986 build and push images (#1093)
Browse files Browse the repository at this point in the history
This PR contains

    Script to build and push images
    Functionality to only build images when relevant code is modified
  • Loading branch information
axsaucedo authored Nov 11, 2019
1 parent 7a684af commit 32710b1
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 18 deletions.
87 changes: 87 additions & 0 deletions ci_build_and_push_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

# FIRST WE START THE DOCKER DAEMON
service docker start
# the service can be started but the docker socket not ready, wait for ready
WAIT_N=0
while true; do
# docker ps -q should only work if the daemon is ready
docker ps -q > /dev/null 2>&1 && break
if [[ ${WAIT_N} -lt 5 ]]; then
WAIT_N=$((WAIT_N+1))
echo "[SETUP] Waiting for Docker to be ready, sleeping for ${WAIT_N} seconds ..."
sleep ${WAIT_N}
else
echo "[SETUP] Reached maximum attempts, not waiting any longer ..."
break
fi
done

#######################################
# AVOID EXIT ON ERROR FOR FOLLOWING CMDS
set +o errexit


echo "Files changed in python folder:"
git --no-pager diff --exit-code --name-only origin/master python
PYTHON_MODIFIED=$?
if [[ $PYTHON_MODIFIED -gt 0 ]]; then
(cd wrappers/s2i/python/build_scripts \
&& ./build_all_local.sh \
&& ./push_all.sh)
PYTHON_EXIT_VALUE=$?
else
echo "SKIPPING PYTHON IMAGE BUILD..."
PYTHON_EXIT_VALUE=0
fi

echo "Files changed in operator folder:"
git --no-pager diff --exit-code --name-only origin/master operator
OPERATOR_MODIFIED=$?
if [[ $OPERATOR_MODIFIED -gt 0 ]]; then
make \
-C operator \
docker-build \
docker-push
OPERATOR_EXIT_VALUE=$?
else
echo "SKIPPING OPERATOR IMAGE BUILD..."
OPERATOR_EXIT_VALUE=0
fi

echo "Files changed in engine folder:"
git --no-pager diff --exit-code --name-only origin/master engine
ENGINE_MODIFIED=$?
if [[ $ENGINE_MODIFIED -gt 0 ]]; then
make \
-C testing/scripts \
build_protos
make \
-C engine \
build_image \
push_to_registry
ENGINE_EXIT_VALUE=$?
else
echo "SKIPPING ENGINE IMAGE BUILD..."
ENGINE_EXIT_VALUE=0
fi



#######################################
# EXIT STOPS COMMANDS FROM HERE ONWARDS
set -o errexit

# CLEANING DOCKER
docker ps -aq | xargs -r docker rm -f || true
service docker stop || true

# NOW THAT WE'VE CLEANED WE CAN EXIT ON TEST EXIT VALUE
exit $((${PYTHON_EXIT_VALUE} \
+ ${OPERATOR_EXIT_VALUE} \
+ ${ENGINE_EXIT_VALUE}))

41 changes: 23 additions & 18 deletions jenkins-x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@ pipelineConfig:
stages:
- name: build-and-test
parallel:
- agent:
- name: test-python
agent:
image: seldonio/python-builder:0.2
name: seldon-python
steps:
- args:
- name: test-python
command: make
args:
- -C python
- update_package
- install_dev
- test
command: make
name: test-python
- agent:
image: seldonio/core-builder:0.4
name: seldon-engine
- name: seldon-engine
steps:
- args:
- -C engine
Expand All @@ -30,22 +28,20 @@ pipelineConfig:
command: make
name: test-engine
release:
setVersion:
steps:
- name: next-version
sh: echo "skipping until 4624 is resolved..."
pipeline:
agent:
image: seldonio/core-builder:0.4
stages:
- name: end-to-end
- name: build-and-push
steps:
- name: test-end-to-end
command: cd
- name: build-and-push-images
command: bash
args:
- ./ci_build_and_push_images.sh
- name: exit-with-error-to-avoid-auto-changelog
command: exit
args:
- testing/scripts &&
- bash
- kind_test_all.sh
- "1"
options:
containerOptions:
volumeMounts:
Expand All @@ -56,6 +52,8 @@ pipelineConfig:
name: cgroup
- name: dind-storage
mountPath: /var/lib/docker
- mountPath: /builder/home/.docker
name: jenkins-docker-config-volume
resources:
requests:
cpu: 1
Expand All @@ -74,3 +72,10 @@ pipelineConfig:
type: Directory
- name: dind-storage
emptyDir: {}
- name: jenkins-docker-config-volume
secret:
items:
- key: config.json
path: config.json
secretName: jenkins-docker-cfg

0 comments on commit 32710b1

Please sign in to comment.