Artifacts persist data after the step is completed and may be used as a storage for deployment packages.
Microtica supports three types of artifacts:
- File Artifacts
- JSON Artifacts
- Docker Artifacts
#File Artifacts
File artifacts are the most common type of artifacts used to produce a deployable package that consists of plain files organized in a folder structure.
YAML
steps:
step_name:
...
artifacts:
files:
[artifact-name]: [path-to-folder-or-files]
Below is an example of a pipeline step that installs node modules and compiles the source code. Once the commands are executed, a new dst/ folder will be created that contains the compiled code with the modules, and we want to package only that folder.
microtica.yaml
steps:
BuildNodeApp:
image: node:latest
commands:
- npm install
- npm run build
artifacts:
files:
primary: dst/
In this case, we’ve defined one artifact named as primary (the name is just a way to recognize multiple artifacts). The artifact will contain all the files and folders inside the local dst/ path.
Packaging contentWhen you want to package a whole folder recursively, make sure that you end the path with a slash (/) so Microtica can distinguish single file from whole folder packaging.
To define an artifact that contains only one specific file just provide the path to the file:
microtica.yaml
steps:
BuildNodeApp:
image: node:latest
commands:
- npm install
- npm run build
artifacts:
files:
primary: dst/index.js
You can also select multiple files by using standard Unix filename wildcard syntax:
microtica.yaml
steps:
BuildNodeApp:
image: node:latest
commands:
- npm install
- npm run build
artifacts:
files:
primary: dst/*.js
The above example will produce an artifact containing all files with .js extension within dst folder.
To define secondary artifacts, just specify them under files.
artifacts:
files:
primary: /dst
assets_artifact: /assets
Microtica will automatically package, store and manage File Artifacts on encrypted, durable blob storage in the cloud.
#JSON Artifacts
Microtica allows you to define structured artifacts in JSON format that you can easily reference from other steps.
Basically, you define the path to the JSON file saved locally during the step execution. Then, the JSON object will become available to reference from other steps using a common JS syntax.
YAML
artifacts:
json: [path-to-json-file]
To demonstrate this, we can define a pipeline that first provisions a complete infrastructure in the cloud to host our SPA website and then deploy the source code on S3.
microtica.yaml
steps:
DeployInfra:
title: Provision SPA infrastructure on AWS
image: hashicorp/terraform:latest
commands:
- terraform init
- terraform apply -auto-approve
- terraform output -json > terraform.output
artifacts:
json: terraform.output
DeployWebsite:
title: Deploy SPA website
image: aws/codebuild/standard:4.0
commands:
- echo Website is being deployed...
# Reference json artifacts from DeployInfra step
- aws s3 sync . ${DeployInfra.artifactsBucket}
- aws cloudfront create-invalidation --distribution-id ${DeployInfra.cdnId}
In the DeployInfra step, Terraform will generate a terraform.output file. This is a JSON file containing the outputs of the provisioned infrastructure.
The DeployWebsite step then references the outputs from the previous step by simply using ${DeployInfra.artifactsBucket} syntax. artifactsBucket is a property from terraform.output file.
Microtica will automatically store and manage JSON Artifacts on encrypted, durable blob storage in the cloud.
#Docker Artifacts
Microtica provides built-in support to build/push Docker images on your preferred Docker registry.
To start working with Docker artifacts you would first need to connect your Docker registry from Microtica Portal.
<image from microtica portal>
The name provided when connecting a new registry will be used in the pipeline yaml to specify the artifacts destination.
Docker artifacts are generated using the built-in Docker Push step by specifying the image name, tag and the Docker registry to be used.
microtica.yaml
steps:
BuildAndPushDocker:
type: docker-push
image_name: microtica/my-app
tag: v0.1.0
dockerfile: Dockerfile
# optional, if not specified, default will be used
registry: my-registry
After BuildAndPushDocker step is completed, image with name my_app_image and tag v0.1.0 will be pushed to my_dockerhub_registry Docker registry connected within Microtica.