Deploy to a Virtual Machine
Deploy to Google Cloud in a Codefresh pipeline with Packer
Even though Codefresh is Kubernetes-native and designed for containers, it can still deploy traditional applications in the form of Virtual Machines to any Cloud provider.
In this example we will use Packer to package an application into a VM disk image that will then be launched in Google Cloud. Because Packer itself is already offered in a Docker container, it is very easy to run Packer in a Codefresh pipeline.
Google also offers a Docker image for GCloud making the launching of the VM straightforward in a Codefresh pipeline.
This Codefresh pipeline creates a VM image and then uses it to launch a Google Compute instance.
The example Packer/Gcloud project
You can see the example project at https://github.com/codefresh-contrib/vm-packer-sample-app. The repository contains a simple Go application as well as a packer template.
You can play with it locally after installing the
You need to create a Codefresh account and a Google account first. Then you need to create a Service account Key which will allow
gcloud to communicate with Google cloud.
Add your service account json as a pipeline variable called
SERVICE_ACCOUNT. The content of this variable will be used
in order to authenticate to Google cloud.
Create a CI/CD pipeline for Packer/GCloud
Here is the whole pipeline:
This pipeline does the following:
- Clones the source code with a Git clone step
- Saves the content of the variable that holds the Google account as a file called
- Compiles the Go application with a freestyle step
packerto create a VM image based on Ubuntu that also contains the simple Go application
gcloudto launch a VM with the image that was just created
Run the pipeline and see your deployment succeed. You can customize the image by editing the Packer template.
Once the VM has finished launching you can access it with your web browser.
You can follow the same procedure for any other cloud that has an API/CLI (such as AWS, Azure, Digital Ocean etc).