Skip to content

Commit

Permalink
fix: add packer, and govc files (#20)
Browse files Browse the repository at this point in the history
* docs: add packer and govc files

* docs: update readme

* Update edge-native/vmware/README.md

* docs: update the dockerfile

* docs: initial commit

* docs: replace PACKER_DEST var in the Dockerfile

* docs: rename edge-native to edge

* docs: update Dockerfile

* docs: separate out manifest

* docs: add readme

* docs: typo

* docs: merge prereqs and requirements

* docs: update readme

* Update terraform/edge-tf/profile.tf

* docs: remove terraform

* docs: remove edge-tf
  • Loading branch information
sudkul87 authored Jul 6, 2023
1 parent c5c6dd1 commit e4cb9ab
Show file tree
Hide file tree
Showing 12 changed files with 441 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ LABEL org.opencontainers.image.description "An image containing all the Spectro

ADD terraform/ /terraform
ADD packs/ /packs
ADD edge/ /edge
ADD static/defaults/htpasswd-basic /auth/htpasswd-basic
ADD static/defaults/ngrok.yml /auth/ngrok.yml
ADD static/defaults/registry-config.yml etc/spectro/config.yml

ARG PALETTE_CLI_VERSION
ARG PALETTE_EDGE_VERSION
ARG PACKER_VERSION=1.8.7

ENV REGISTRY_LOG_LEVEL=info
ENV REGISTRY_AUTH=htpasswd
ENV REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"
ENV REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd-basic

COPY --from=server /registry /usr/local/bin/
COPY --from=server /etc/spectro/config.yml /etc/spectro/config.yml

RUN adduser -H -u 1002 -D appuser appuser && \
apk update && \
Expand Down Expand Up @@ -49,7 +52,10 @@ RUN wget https://software.spectrocloud.com/spectro-registry/v$PALETTE_CLI_VERSI
git clone https://github.com/spectrocloud/CanvOS.git && \
rm -rf /var/cache/apk/*


ADD https://releases.hashicorp.com/packer/${PACKER_VERSION}/packer_${PACKER_VERSION}_linux_amd64.zip /usr/local/sbin/
RUN unzip /usr/local/sbin/packer_${PACKER_VERSION}_linux_amd64.zip -d /usr/local/sbin && \
rm -rf /usr/local/sbin/packer_${PACKER_VERSION}_linux_amd64.zip
RUN apk add xorriso govc
EXPOSE 5000

CMD ["/bin/bash"]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ init:

build-docker:
@echo "Building docker image"
docker build --build-arg PALETTE_VERSION=$(VERSION) --build-arg PALETTE_CLI_VERSION=$(VERSION) --build-arg PALETTE_EDGE_VERSION=$(EDGE) -t tutorials .
docker build --build-arg PALETTE_VERSION=$(VERSION) --build-arg PALETTE_CLI_VERSION=$(VERSION) --build-arg PALETTE_EDGE_VERSION=$(EDGE) --build-arg PACKER_VERSION=1.8.7 -t tutorials .
4 changes: 3 additions & 1 deletion docs/docker.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The Docker image includes the following tools.
| `ca-certificates` | Common set of CA certificates |
| `canvos` | A utility for creating Edge artifacts |
| `nano` | A text editior for Unix-like computing systems or operating environments using a command line interface|
| `packer` | Hashicorp Image Builder for building Edge Native images |
| `GOVC` | Tool for interracting with VMware Vsphere via API |

### Spectro Cloud Pack Registry Server

Expand Down Expand Up @@ -67,6 +69,6 @@ make build-docker VERSION=3.4.0 EDGE=3.4.3
OR

```shell
docker build --build-arg PALETTE_VERSION=3.3.0 --build-arg PALETTE_CLI_VERSION=3.4.0 --build-arg PALETTE_EDGE_VERSION=3.4.3 -t tutorials .
docker build --build-arg PALETTE_VERSION=3.3.0 --build-arg PALETTE_CLI_VERSION=3.4.0 --build-arg PALETTE_EDGE_VERSION=3.4.3 --build-arg PACKER_VERSION=1.8.7 -t tutorials .
```

77 changes: 77 additions & 0 deletions edge/vmware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Overview
This directory contains the files referenced in the [Deploy an Edge Cluster on VMware](https://docs.spectrocloud.com/clusters/edge/deploy-cluster) tutorial. Use the files in this directory with the tutorial. The following code block shows the list of files.


```bash
.
└── vmware
├── README.md
├── clone_vm_template
│   ├── delete-edge-host.sh # Deletes the VMs
│   ├── deploy-edge-host.sh # Provisions the VMs
│   └── setenv.sh # Defines the GOVC environment variables
└── packer
├── build.pkr.hcl # Packer build script
├── meta-data # Sample template
├── user-data # Sample template
└── vsphere.hcl # Contains the VM template name, VM configuration, and ISO file name
```


The **vmware/packer/** folder contains the Packer code responsible for creating a VM template in VMWare vCenter from the Edge installer ISO image. Here is a brief description of files present in this folder:

- **build.pkr.hcl** is the Packer build script.

- **vsphere.hcl** defines the VM template name, VM configuration, and ISO file name to use. The VM configuration conforms to the [minimum device requirements](https://docs.spectrocloud.com/clusters/edge/architecture/#minimumdevicerequirements).

- **meta-data** and **user-data** are sample template files. These file are optional for the build process.


The **vmware/clone_vm_template** folder contains the shell scripts containing GOVC command line instructions. Here is a brief description of the files present in this folder:

- **delete-edge-host.sh** provisions the VMs

- **deploy-edge-host.sh** deletes the VMs.

- **setenv.sh** defines the GOVC environment variables, the number of VMs, a prefix string for the VM name, and the VM template name.

# Dependencies
Your environment must have Packer and GOVC installed. The tutorials container comes with these dependencies pre-installed. If you are not using the tutorials container, you must install these dependencies on your machine. Here are the instructions to install these on a Linux machine.

To install Packer, refer to these official [instructions](https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli).

To install GOVC, you must first install Go using the following instructions:
```bash
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
```
After installing Go, you can install [GOVC CLI utility](https://github.com/vmware/govmomi/tree/main/govc) and `xorriso` dependency as:
```bash
curl -L -o - "https://github.com/vmware/govmomi/releases/latest/download/govc_$(uname -s)_$(uname -m).tar.gz" | tar -C /usr/local/bin -xvzf - govc
sudo apt-get install -y xorriso
```


# Prerequisites
To use the Packer and GOVC files, you need the following VMWare permissions:

```bash
Datastore.AllocateSpace
Host.Config.AdvancedConfig
Host.Config.NetService
Host.Config.Network
Network.Assign
System.Anonymous
System.Read
System.View
VApp.Import
VirtualMachine.Config.AddNewDisk
VirtualMachine.Config.AdvancedConfig
```

You will need the VMWare vCenter server URL, login credentials, and names of the data center, destination datastore, resource pool, destination folder (not on Datastore, on the vSphere logical view), cluster, and DHCP enabled network to be assigned to the VM template.


Refer to the [Deploy an Edge Cluster on VMware](https://docs.spectrocloud.com/clusters/edge/deploy-cluster) tutorial to learn how to use Packer and GOVC files present in this folder.
22 changes: 22 additions & 0 deletions edge/vmware/clone_vm_template/delete-edge-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

source ./setenv.sh

set -o errexit
set -o nounset
set -o pipefail

vm_array=( $(seq 1 $NO_OF_VMS ) )


echo "Cleaning Previous VMs on vSphere"

for VM in ${vm_array[@]};
do
echo "Getting UUID $VM_PREFIX-$VM"
UUID=$(govc vm.info $VM_PREFIX-$VM | grep UUID: | sed "s/.* //" | sed "s/-//g")
if govc vm.destroy $VM_PREFIX-$VM #> /dev/null 2>&1
then
echo "Deleted $VM_PREFIX-$VM"
fi
done
33 changes: 33 additions & 0 deletions edge/vmware/clone_vm_template/deploy-edge-host.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/bin/bash

source ./setenv.sh

set -o errexit
set -o nounset
set -o pipefail

vm_array=( $(seq 1 $NO_OF_VMS ) )


for VM in ${vm_array[@]};
do
if govc vm.clone -link=true -m 8000 -on=false -vm $GOVC_FOLDER/$INSTALLER_TEMPLATE $VM_PREFIX-$VM
then
echo "Cloned VM $VM_PREFIX-$VM"
else
echo "Failed to clone VM $VM_PREFIX-$VM"
fi

echo "Powering on VM $VM_PREFIX-$VM"
if ! govc vm.power -on=true -wait=false $VM_PREFIX-$VM
then
echo "Failed to power on VM $VM_PREFIX-$VM"
fi

echo "Getting UUID $VM_PREFIX-$VM"
# govc vm.info got uuid with middle ending, need to convert the first 3 components
u=$(govc vm.info $VM_PREFIX-$VM | grep UUID: | sed "s/.* //" | sed "s/-//g")
UUID=${u:6:2}${u:4:2}${u:2:2}${u:0:2}${u:10:2}${u:8:2}${u:14:2}${u:12:2}${u:16}
echo "Edge Host ID VM $VM_PREFIX-$VM : edge-$UUID"
done

21 changes: 21 additions & 0 deletions edge/vmware/clone_vm_template/setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
# Number of VMs to provision
export NO_OF_VMS=3
export VM_PREFIX="demo"
export INSTALLER_TEMPLATE="palette-edge-template"

##################################################
#### DO NOT MODIFY BELOW HERE ####################
##################################################

# GOVC Properties
# vCenter Endpoint
export GOVC_URL="https://${vcenter_server}" # Use HTTPS. For example, https://vcenter.company.com
export GOVC_USERNAME="${vcenter_username}"
export GOVC_PASSWORD="${vcenter_password}"
export GOVC_INSECURE=1 #1 if insecure
export GOVC_DATACENTER="${vcenter_datacenter}"
export GOVC_DATASTORE="${vcenter_datastore}"
export GOVC_NETWORK="${vcenter_network}"
export GOVC_RESOURCE_POOL="${vcenter_resource_pool}"
export GOVC_FOLDER="${vcenter_folder}"
21 changes: 21 additions & 0 deletions edge/vmware/packer/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
export vcenter_server="Enter a value" # Example: vcenter.spectrocloud.dev
export vcenter_username="Enter a value"
export vcenter_password="Enter a value"
export vcenter_datacenter="Enter a value"
export vcenter_datastore="Enter a value"
export vcenter_resource_pool="Enter a value"
export vcenter_folder="Enter a value"
export vcenter_cluster="Enter a value"
export vcenter_network="Enter a value"


export PKR_VAR_vcenter_server=${vcenter_server}
export PKR_VAR_vcenter_username=${vcenter_username}
export PKR_VAR_vcenter_password=${vcenter_password}
export PKR_VAR_vcenter_datacenter=${vcenter_datacenter}
export PKR_VAR_vcenter_datastore=${vcenter_datastore}
export PKR_VAR_vcenter_resource_pool=${vcenter_resource_pool}
export PKR_VAR_vcenter_folder=${vcenter_folder}
export PKR_VAR_vcenter_cluster=${vcenter_cluster}
export PKR_VAR_vcenter_network=${vcenter_network}
Loading

0 comments on commit e4cb9ab

Please sign in to comment.