Blueprints are a key feature of XebiaLabs’ DevOps as Code approach; they guide teams through a fast, easy process that automatically generates YAML files that describe applications, infrastructure, and more as code that can be checked into a source control management system. Blueprints allow you to embed corporate policies, security requirements, and best practices in code that you can share across the enterprise, so it’s easier to on-board teams to the DevOps toolchain and migrate applications to new technologies such as container platforms and cloud-based environments.
XebiaLabs provides sample blueprints that help you migrate applications to platforms such as Amazon ECS and EKS—but you can build your own blueprints, too! For example, say you want to make it easy for Jane, a new developer, to deploy Docker containers on her local Docker installation. Let’s see what that would look like.
Step 1 Build the blueprint YAML file
The blueprint YAML file provides the questions that Jane will answer, defines default answers where needed, and identifies the templates (tmpl
files) that the XL command-line interface (CLI) should use for the output. This example assumes that Jane’s application is packaged in two Docker images: one for the front end, and one for the back end.
apiVersion: xl/v1 kind: Blueprint metadata: projectName: Docker Demo Application description: | The blueprint deploys a simple application in 2 Docker containers into your local Docker setup. author: XebiaLabs version: 1.0 parameters: - name: AppName type: Input description: What is the Application name? - name: ContainerPort type: Input description: At what port should the application be exposed in the container? default: 80 - name: HostPort type: Input description: At what port should the container port be mapped in the host? default: 8181 - name: BackendDockerImage type: Input description: What is the Docker Image (repo and path) for the Backend service? default: xebialabsunsupported/rest-o-rant-api - name: FrontendDockerImage type: Input description: What is the Docker Image (repo and path) for the Frontend service? default: xebialabsunsupported/rest-o-rant-web files: - path: xebialabs/xld-environment.yaml.tmpl - path: xebialabs/xld-docker-apps.yaml.tmpl - path: xebialabs/xlr-pipeline.yaml.tmpl - path: xebialabs.yaml
Step 2 Encode best practices in YAML templates
The magic of blueprints lies in templates for the YAML files that the XL CLI will generate. Templates enable you to build corporate requirements and technical best practices directly in code—no need for Jane to know the ins and outs of the target configuration.
In a template, the values between double curly brackets will be replaced with information that’s specific Jane’s application and Docker setup. For example, this template requires an application name, the names of the two Docker images, and the port bindings to pass to the Docker installation.
{{$app := .AppName | kebabcase}} apiVersion: xl-deploy/v1 kind: Applications spec: - name: {{$app}} type: core.Directory children: - name: {{$app}}-backend type: udm.Application children: - name: '1.0' type: udm.DeploymentPackage deployables: - name: {{$app}}-network type: docker.NetworkSpec networkName: {{$app}} driver: bridge - name: {{$app}}-backend type: docker.ContainerSpec image: {{.BackendDockerImage}} networks: - {{$app}} showLogsAfter: 5 - name: {{$app}}-frontend type: udm.Application children: - name: '1.0' type: udm.DeploymentPackage orchestrator: - sequential-by-dependency deployables: - name: {{$app}}-frontend type: docker.ContainerSpec image: {{.FrontendDockerImage}} networks: - {{$app}} showLogsAfter: 5 portBindings: - name: ports type: docker.PortSpec hostPort: {{.HostPort}} containerPort: {{.ContainerPort}} protocol: tcp environment: API_ENDPOINT: http://{{$app}}-backend:8080/rest-o-rant-api
Step 3 Run the blueprint!
Jane just needs to install the XL CLI, execute xl blueprint
, select the blueprint, and answer the questions that are defined in the blueprint YAML file.
The XL CLI uses Jane’s answers to generate YAML files based on the templates that you created. The xebialabs.yaml
file points to the other generated files, so that Jane can later apply everything with a single CLI command.
In this case, Jane didn’t need to provide any sensitive data; but if that was required, the data would be stored in xlvals
files. The gitignore
file ensures that Jane doesn’t accidentally check sensitive data into source control management.
Step 4 Check out the YAML
Here’s the YAML file that is generated, based on the template above:
apiVersion: xl-deploy/v1 kind: Applications spec: - name: rest-o-rant type: core.Directory children: - name: rest-o-rant-backend type: udm.Application children: - name: '1.0' type: udm.DeploymentPackage deployables: - name: rest-o-rant-network type: docker.NetworkSpec networkName: rest-o-rant driver: bridge - name: rest-o-rant-backend type: docker.ContainerSpec image: xebialabsunsupported/rest-o-rant-api networks: - rest-o-rant showLogsAfter: 5 - name: rest-o-rant-frontend type: udm.Application children: - name: '1.0' type: udm.DeploymentPackage orchestrator: - sequential-by-dependency deployables: - name: rest-o-rant-frontend type: docker.ContainerSpec image: xebialabsunsupported/rest-o-rant-web networks: - rest-o-rant showLogsAfter: 5 portBindings: - name: ports type: docker.PortSpec hostPort: 8181 containerPort: 80 protocol: tcp environment: API_ENDPOINT: http://rest-o-rant-backend:8080/rest-o-rant-api
Jane can check the generated YAML files into a source control management (SCM) system, in the same repository as her application code. SCM will secure the YAML files and make it easy for Jane’s team to collaborate on any modifications that are required in the future. SCM also tracks their changes and version-controls the files, so it’s easy to roll back unwanted changes.
Step 5 Bring it all together
After the YAML files are generated, Jane can put them to use! A simple xl apply
command sends the YAML to the XebiaLabs DevOps Platform, which creates the required configuration items and release template.
Try it yourself
Are you using Docker? You can try this blueprint today! Just download the XL CLI and execute xl blueprint
to access XebiaLabs’ publicly available blueprints. If you aren’t using the XebiaLabs DevOps Platform yet, sign up for a free trial to get started.
Check out a demo featuring Amazon EKS
Are you interested in a more advanced blueprint scenario? Check out this video, which shows how you can use DevOps as Code to deploy a microservice-based application on Amazon EKS.
Learn More
- All Aboard! Get Everyone on the DevOps Train with XebiaLabs Blueprints
- Go Code-native with DevOps as Code
- Accelerate DevOps Transformation with App Migration to the Cloud
- Try the XebiaLabs DevOps Platform for free
The post Blueprint Walkthrough: Deploy a Docker Container appeared first on XebiaLabs Blog.