Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
Deploy on RHEL based container (#3317)
Browse files Browse the repository at this point in the history
Enable build on RHEL if TARGET=rhel.

As part of an effort to migrate the services running in OSIO from CentOS
to RHEL, we are ready to push out the RHEL based image for this service
into staging.

This PR includes a new RHEL based dockerfile for the deployment of the service.
This dockerfile will be built when this variable is set: TARGET=rhel. The build
scripts have been adapted to take this into consideration, and to push the image
to different namespaces if the TARGET is rhel or not.

Currently the deployment builds happen on empty baremetal machines. The build
script will be executed a second time to build and push the deployment file if
TARGET=rhel, so some changes in the build script are to ensure that it will work
if executed a second time.

The OpenShift template has also been patched so it allows parametrization for
the container IMAGE, enabling the possibility of having different IMAGE urls for
staging and for production.

By merging this PR this service will be deployed to staging. Once we verify that
the RHEL based image works correctly, we can push to prod.
  • Loading branch information
jmelis authored and kbsingh committed Apr 26, 2018
1 parent 2ace40a commit 71be59f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 57 deletions.
13 changes: 13 additions & 0 deletions Dockerfile.deploy.rhel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM prod.registry.devshift.net/osio-prod/base/fabric8-openshift-nginx:latest
LABEL maintainer "Devtools <[email protected]>"
LABEL author "Devtools <[email protected]>"

USER root

ADD nginx.conf /etc/nginx/nginx.conf

RUN rm -rf /usr/share/nginx/html/
COPY dist /usr/share/nginx/html
RUN chmod -R 777 /usr/share/nginx/html/

USER ${FABRIC8_USER_NAME}
95 changes: 40 additions & 55 deletions cico_build_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,80 +1,65 @@
#!/bin/bash

REGISTRY="push.registry.devshift.net"
DEPLOY_CONT="wwwopenshiftio-deploy"
BUILDER_CONT="wwwopenshiftio-builder"

if [ "$TARGET" = "rhel" ]; then
DOCKERFILE_DEPLOY="Dockerfile.deploy.rhel"
REGISTRY_URL=${REGISTRY}/osio-prod/fabric8io/wwwopenshiftio
else
DOCKERFILE_DEPLOY="Dockerfile.deploy"
REGISTRY_URL=${REGISTRY}/fabric8io/wwwopenshiftio
fi

# Show command before executing
set -x

# Exit on error
set -e

# Export needed vars
set +x
for var in BUILD_NUMBER BUILD_URL GIT_COMMIT DEVSHIFT_USERNAME DEVSHIFT_PASSWORD DEVSHIFT_TAG_LEN; do
export $(grep ${var} jenkins-env | xargs)
done
export BUILD_TIMESTAMP=`date -u +%Y-%m-%dT%H:%M:%S`+00:00
set -x

# We need to disable selinux for now, XXX
/usr/sbin/setenforce 0
/usr/sbin/setenforce 0 || :

# Get all the deps in
yum -y install docker
yum clean all
service docker start

# Build builder image
docker build -t wwwopenshiftio-builder -f Dockerfile.builder .
mkdir -p dist && docker run --detach=true --name=wwwopenshiftio-builder -t -v $(pwd)/dist:/dist:Z -e BUILD_NUMBER -e BUILD_URL -e BUILD_TIMESTAMP wwwopenshiftio-builder
docker build -t "${BUILDER_CONT}" -f Dockerfile.builder .

# Clean builder container
docker ps | grep -q "${BUILDER_CONT}" && docker stop "${BUILDER_CONT}"
docker ps -a | grep -q "${BUILDER_CONT}" && docker rm "${BUILDER_CONT}"

mkdir -p dist && docker run --detach=true --name="${BUILDER_CONT}" -t -v $(pwd)/dist:/dist:Z -e BUILD_NUMBER -e BUILD_URL -e BUILD_TIMESTAMP "${BUILDER_CONT}"

# Build almigty-ui
docker exec wwwopenshiftio-builder npm install

## Exec unit tests
#docker exec wwwopenshiftio-builder ./run_unit_tests.sh

#if [ $? -eq 0 ]; then
# echo 'CICO: unit tests OK'
#else
# echo 'CICO: unit tests FAIL'
# exit 1
#fi

## Exec functional tests
#docker exec wwwopenshiftio-builder ./run_functional_tests.sh

#if [ $? -eq 0 ]; then
# echo 'CICO: functional tests OK'
docker exec wwwopenshiftio-builder npm run build:prod
docker exec -u root wwwopenshiftio-builder cp -r /home/fabric8/wwwopenshiftio/dist /
## All ok, deploy
# if [ $? -eq 0 ]; then
# echo 'CICO: build OK'
docker build -t wwwopenshiftio-deploy -f Dockerfile.deploy . && \

TAG=$(echo $GIT_COMMIT | cut -c1-${DEVSHIFT_TAG_LEN})
REGISTRY="push.registry.devshift.net"

if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then
docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY}
else
echo "Could not login, missing credentials for the registry"
fi

docker tag wwwopenshiftio-deploy ${REGISTRY}/fabric8io/wwwopenshiftio:$TAG && \
docker push ${REGISTRY}/fabric8io/wwwopenshiftio:$TAG && \
docker tag wwwopenshiftio-deploy ${REGISTRY}/fabric8io/wwwopenshiftio:latest && \
docker push ${REGISTRY}/fabric8io/wwwopenshiftio:latest
if [ $? -eq 0 ]; then
echo 'CICO: image pushed, ready to update deployed app'
exit 0
else
echo 'CICO: Image push to registry failed'
exit 2
fi
# else
# echo 'CICO: app tests Failed'
# exit 1
# fi
#else
# echo 'CICO: functional tests FAIL'
# exit 1
#fi
docker exec "${BUILDER_CONT}" npm install
docker exec "${BUILDER_CONT}" npm run build:prod
docker exec -u root "${BUILDER_CONT}" cp -r /home/fabric8/wwwopenshiftio/dist /

if [ -n "${DEVSHIFT_USERNAME}" -a -n "${DEVSHIFT_PASSWORD}" ]; then
docker login -u ${DEVSHIFT_USERNAME} -p ${DEVSHIFT_PASSWORD} ${REGISTRY}
else
echo "Could not login, missing credentials for the registry"
fi

docker build -t "${DEPLOY_CONT}" -f "${DOCKERFILE_DEPLOY}" .

TAG=$(echo $GIT_COMMIT | cut -c1-${DEVSHIFT_TAG_LEN})

docker tag "${DEPLOY_CONT}" "${REGISTRY_URL}:$TAG"
docker push "${REGISTRY_URL}:$TAG"

docker tag "${DEPLOY_CONT}" "${REGISTRY_URL}:latest"
docker push "${REGISTRY_URL}:latest"
5 changes: 3 additions & 2 deletions openshift/www.openshift.io.app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ objects:
service: wwwopenshiftio
spec:
containers:
- image: registry.devshift.net/fabric8io/wwwopenshiftio:${IMAGE_TAG}
- image: ${IMAGE}:${IMAGE_TAG}
imagePullPolicy: Always
name: wwwopenshiftio
ports:
Expand Down Expand Up @@ -123,6 +123,7 @@ objects:
wildcardPolicy: None
status: {}
parameters:
- name: IMAGE
value: registry.devshift.net/fabric8io/wwwopenshiftio
- name: IMAGE_TAG
value: latest

0 comments on commit 71be59f

Please sign in to comment.