Request A Demo
Back to All Blog Articles

FlexDeploy loves Functions: Build Docker Containers with Fn Functions

This is the fourth article in the blog series on what makes FlexDeploy a perfect fit for container native technologies:

In this post I am going to show how FlexDeploy can leverage Serverless paradigm and use Fn Project functions in a build workflow.

Let’s consider a simple workflow like this:

The goal of this workflow is to build an Oracle Jet application, save the web folder to an artifact repository, build a docker image containing the Jet application and Nginx web server and push the docker image to Docker Hub registry.

The first step of the build workflow Build OJet Application is a Shell plugin operation which invokes an Fn function building an Oracle JET application, zipping the web folder and pushing the zip file to a Nexus repository. The invocation of the function looks like this:

curl $FN_APP_URL/build -d "$NEXUS_USER $NEXUS_PWD $NEXUS_URL $FD_PROJECT_VERSION"

The build Fn function is going to be based on a docker image which we can build with the following Dockerfile:

# Create an image from a "builder" Docker image
# See http://adfpractice-fedor.blogspot.com/2018/04/building-oracle-jet-applications-with.html
FROM eugeneflexagon/ojetbuilder

# install zip 
RUN apt-get update
RUN apt-get install zip -y

# install git 
RUN apt install git-all -y


# copy into container a shell script performing the build
COPY build.sh /usr/local/bin/build.sh
RUN chmod +x /usr/local/bin/build.sh

ENTRYPOINT ["xargs","/usr/local/bin/build.sh"]

So, let’s build and push the image to Docker Hub:

docker build -t eugeneflexagon/ojetbuilderfn .
docker push eugeneflexagon/ojetbuilderfn

The image eugeneflexagon/ojetbuilderfn contains git client to fetch source code of the Jet application, OJET Cli to build the application and zip to archive the web folder (result of the build). It also contains build.sh shell script which actually, builds, zips and pushes the archive to the Nexus repository:

#!/bin/bash

# Clone the source code
git clone https://github.com/eedorenko/ojetdevops.git

# Build the application
cd ojetdevops
ojet build

# Archive the web folder
zip -r web web/*

# Push the archive to Nexus
curl -v  -u $1:$2 --upload-file web.zip http://$3/nexus/content/repositories/snapshots/jet/$4/web.zip

The script accepts four parameters: Nexus username/password, Nexus url and project version to organize Jet archives in the Nexus snapshot repository nicely:

 

Having eugeneflexagon/ojetbuilderfn Docker image created we can define the build function which is invoked by Build OJet Application workflow step:

fn apps create ojetbuilder
fn routes create ojetbuilder /build eugeneflexagon/ojetbuilderfn:latest

The next step of the workflow Build Docker Image invokes Docker plugin operation buildImage to build a Docker image containing Oracle JET application and a web server:

The image is going to be built with the following Dockerfile:

# Create a Docker image which runs Jet application
# It contains Nginx on top of Alpine and our Jet appliction (web folder)
# This image is the result of the build and it is going to be stored in Docker Hub
FROM nginx:1.10.2-alpine
COPY web /usr/share/nginx/html
EXPOSE 80

The last step of the workflow Push Docker Image invokes Docker plugin operation pushImage to push the image to Docker Hub:

 

Having the image pushed to Docker Hub we can pull it and run the container locally:

docker run -it -p 8082:80 eugeneflexagon/ojetdevops:latest

And see the result at http://localhost:8082, or we can deploy the image to a K8s cluster with deploy function as it was described in the previous post.

 

That’s it!

Previous Post: FlexDeploy Loves Functions: Deploy Docker Containers with Fn Functions

Next Post: FlexDeploy is a Container: Run FlexDeploy as a Docker Container

Related Resources

Unlock the Power of DevOps Compliance for Your Enterprise Software

In today’s fast-paced software development environment, ensuring compliance with regulatory standards and policies is not just a necessity—it’s a strategic ...

Integrating Tricentis Tosca (DEX) with FlexDeploy for Test Automation

Tricentis Tosca is a software testing tool that is used to automate end-to-end testing for software applications. Tricentis Tosca combines ...

Integrating ACCELQ with FlexDeploy for Seamless Test Automation

ACCELQ is a cloud-based, continuous testing platform that offers codeless test automation for web, mobile, API, desktop, and packaged applications. ...

Join DevOps leaders across the globe who receive analysis, tips, and trends in their inbox