This is the fourth article in the blog series on what makes FlexDeploy a perfect fit for container native technologies:
- FlexDeploy Loves Containers: Build and Deploy Microservices to Kubernetes clusters in the Cloud
- Enrich Oracle Container Native Application Development Platform with FlexDeploy Pipelines
- FlexDeploy Loves Functions: Deploy Docker Containers with Fn Functions
- FlexDeploy loves Functions: Build Docker Containers with Fn Functions
- FlexDeploy is a Container: Run FlexDeploy as a Docker Container
- FlexDeploy Loves Containers: Build FlexDeploy Plugins with Docker
Want to follow along in FlexDeploy? Check out our JumpStart Demo Lab configured with Docker and Kubernetes. This is a pre-configured, friction-free environment in the cloud for you to try FlexDeploy with no set up, installation, or configuration.
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