Skip to content

Commit e4cb9ab

Browse files
authored
fix: add packer, and govc files (#20)
* 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
1 parent c5c6dd1 commit e4cb9ab

File tree

12 files changed

+441
-3
lines changed

12 files changed

+441
-3
lines changed

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ LABEL org.opencontainers.image.description "An image containing all the Spectro
99

1010
ADD terraform/ /terraform
1111
ADD packs/ /packs
12+
ADD edge/ /edge
1213
ADD static/defaults/htpasswd-basic /auth/htpasswd-basic
1314
ADD static/defaults/ngrok.yml /auth/ngrok.yml
1415
ADD static/defaults/registry-config.yml etc/spectro/config.yml
1516

1617
ARG PALETTE_CLI_VERSION
1718
ARG PALETTE_EDGE_VERSION
19+
ARG PACKER_VERSION=1.8.7
1820

1921
ENV REGISTRY_LOG_LEVEL=info
2022
ENV REGISTRY_AUTH=htpasswd
2123
ENV REGISTRY_AUTH_HTPASSWD_REALM="Registry Realm"
2224
ENV REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd-basic
2325

2426
COPY --from=server /registry /usr/local/bin/
27+
COPY --from=server /etc/spectro/config.yml /etc/spectro/config.yml
2528

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

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

5561
CMD ["/bin/bash"]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ init:
33

44
build-docker:
55
@echo "Building docker image"
6-
docker build --build-arg PALETTE_VERSION=$(VERSION) --build-arg PALETTE_CLI_VERSION=$(VERSION) --build-arg PALETTE_EDGE_VERSION=$(EDGE) -t tutorials .
6+
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 .

docs/docker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The Docker image includes the following tools.
3838
| `ca-certificates` | Common set of CA certificates |
3939
| `canvos` | A utility for creating Edge artifacts |
4040
| `nano` | A text editior for Unix-like computing systems or operating environments using a command line interface|
41+
| `packer` | Hashicorp Image Builder for building Edge Native images |
42+
| `GOVC` | Tool for interracting with VMware Vsphere via API |
4143

4244
### Spectro Cloud Pack Registry Server
4345

@@ -67,6 +69,6 @@ make build-docker VERSION=3.4.0 EDGE=3.4.3
6769
OR
6870

6971
```shell
70-
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 .
72+
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 .
7173
```
7274

edge/vmware/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Overview
2+
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.
3+
4+
5+
```bash
6+
.
7+
└── vmware
8+
├── README.md
9+
├── clone_vm_template
10+
│   ├── delete-edge-host.sh # Deletes the VMs
11+
│   ├── deploy-edge-host.sh # Provisions the VMs
12+
│   └── setenv.sh # Defines the GOVC environment variables
13+
└── packer
14+
├── build.pkr.hcl # Packer build script
15+
├── meta-data # Sample template
16+
├── user-data # Sample template
17+
└── vsphere.hcl # Contains the VM template name, VM configuration, and ISO file name
18+
```
19+
20+
21+
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:
22+
23+
- **build.pkr.hcl** is the Packer build script.
24+
25+
- **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).
26+
27+
- **meta-data** and **user-data** are sample template files. These file are optional for the build process.
28+
29+
30+
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:
31+
32+
- **delete-edge-host.sh** provisions the VMs
33+
34+
- **deploy-edge-host.sh** deletes the VMs.
35+
36+
- **setenv.sh** defines the GOVC environment variables, the number of VMs, a prefix string for the VM name, and the VM template name.
37+
38+
# Dependencies
39+
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.
40+
41+
To install Packer, refer to these official [instructions](https://developer.hashicorp.com/packer/tutorials/docker-get-started/get-started-install-cli).
42+
43+
To install GOVC, you must first install Go using the following instructions:
44+
```bash
45+
wget https://go.dev/dl/go1.20.5.linux-amd64.tar.gz
46+
sudo tar -C /usr/local -xzf go1.20.5.linux-amd64.tar.gz
47+
export PATH=$PATH:/usr/local/go/bin
48+
go version
49+
```
50+
After installing Go, you can install [GOVC CLI utility](https://github.com/vmware/govmomi/tree/main/govc) and `xorriso` dependency as:
51+
```bash
52+
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
53+
sudo apt-get install -y xorriso
54+
```
55+
56+
57+
# Prerequisites
58+
To use the Packer and GOVC files, you need the following VMWare permissions:
59+
60+
```bash
61+
Datastore.AllocateSpace
62+
Host.Config.AdvancedConfig
63+
Host.Config.NetService
64+
Host.Config.Network
65+
Network.Assign
66+
System.Anonymous
67+
System.Read
68+
System.View
69+
VApp.Import
70+
VirtualMachine.Config.AddNewDisk
71+
VirtualMachine.Config.AdvancedConfig
72+
```
73+
74+
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.
75+
76+
77+
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.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
source ./setenv.sh
4+
5+
set -o errexit
6+
set -o nounset
7+
set -o pipefail
8+
9+
vm_array=( $(seq 1 $NO_OF_VMS ) )
10+
11+
12+
echo "Cleaning Previous VMs on vSphere"
13+
14+
for VM in ${vm_array[@]};
15+
do
16+
echo "Getting UUID $VM_PREFIX-$VM"
17+
UUID=$(govc vm.info $VM_PREFIX-$VM | grep UUID: | sed "s/.* //" | sed "s/-//g")
18+
if govc vm.destroy $VM_PREFIX-$VM #> /dev/null 2>&1
19+
then
20+
echo "Deleted $VM_PREFIX-$VM"
21+
fi
22+
done
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
source ./setenv.sh
4+
5+
set -o errexit
6+
set -o nounset
7+
set -o pipefail
8+
9+
vm_array=( $(seq 1 $NO_OF_VMS ) )
10+
11+
12+
for VM in ${vm_array[@]};
13+
do
14+
if govc vm.clone -link=true -m 8000 -on=false -vm $GOVC_FOLDER/$INSTALLER_TEMPLATE $VM_PREFIX-$VM
15+
then
16+
echo "Cloned VM $VM_PREFIX-$VM"
17+
else
18+
echo "Failed to clone VM $VM_PREFIX-$VM"
19+
fi
20+
21+
echo "Powering on VM $VM_PREFIX-$VM"
22+
if ! govc vm.power -on=true -wait=false $VM_PREFIX-$VM
23+
then
24+
echo "Failed to power on VM $VM_PREFIX-$VM"
25+
fi
26+
27+
echo "Getting UUID $VM_PREFIX-$VM"
28+
# govc vm.info got uuid with middle ending, need to convert the first 3 components
29+
u=$(govc vm.info $VM_PREFIX-$VM | grep UUID: | sed "s/.* //" | sed "s/-//g")
30+
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}
31+
echo "Edge Host ID VM $VM_PREFIX-$VM : edge-$UUID"
32+
done
33+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# Number of VMs to provision
3+
export NO_OF_VMS=3
4+
export VM_PREFIX="demo"
5+
export INSTALLER_TEMPLATE="palette-edge-template"
6+
7+
##################################################
8+
#### DO NOT MODIFY BELOW HERE ####################
9+
##################################################
10+
11+
# GOVC Properties
12+
# vCenter Endpoint
13+
export GOVC_URL="https://${vcenter_server}" # Use HTTPS. For example, https://vcenter.company.com
14+
export GOVC_USERNAME="${vcenter_username}"
15+
export GOVC_PASSWORD="${vcenter_password}"
16+
export GOVC_INSECURE=1 #1 if insecure
17+
export GOVC_DATACENTER="${vcenter_datacenter}"
18+
export GOVC_DATASTORE="${vcenter_datastore}"
19+
export GOVC_NETWORK="${vcenter_network}"
20+
export GOVC_RESOURCE_POOL="${vcenter_resource_pool}"
21+
export GOVC_FOLDER="${vcenter_folder}"

edge/vmware/packer/.env

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
export vcenter_server="Enter a value" # Example: vcenter.spectrocloud.dev
3+
export vcenter_username="Enter a value"
4+
export vcenter_password="Enter a value"
5+
export vcenter_datacenter="Enter a value"
6+
export vcenter_datastore="Enter a value"
7+
export vcenter_resource_pool="Enter a value"
8+
export vcenter_folder="Enter a value"
9+
export vcenter_cluster="Enter a value"
10+
export vcenter_network="Enter a value"
11+
12+
13+
export PKR_VAR_vcenter_server=${vcenter_server}
14+
export PKR_VAR_vcenter_username=${vcenter_username}
15+
export PKR_VAR_vcenter_password=${vcenter_password}
16+
export PKR_VAR_vcenter_datacenter=${vcenter_datacenter}
17+
export PKR_VAR_vcenter_datastore=${vcenter_datastore}
18+
export PKR_VAR_vcenter_resource_pool=${vcenter_resource_pool}
19+
export PKR_VAR_vcenter_folder=${vcenter_folder}
20+
export PKR_VAR_vcenter_cluster=${vcenter_cluster}
21+
export PKR_VAR_vcenter_network=${vcenter_network}

0 commit comments

Comments
 (0)