Skip to content

Commit d525fc6

Browse files
lennessyykarl-cardenas-codingcaroldelwing
authored
fix: added new tools such as oras and awscli, and script to check for and delete packer cache (#24)
* fix: added script to check for and delete packer cache * fix: added new tools such as oras and awscli, updated Terraform files * Apply suggestions from code review Co-authored-by: Karl Cardenas <karl@spectrocloud.com> * Update edge/vmware/clone_vm_template/delete-packer-cache.sh change error output destination * fix: added new tools such as oras and awscli, updated Terraform files… (#25) * fix: added new tools such as oras and awscli, updated Terraform files to include OCI registries * chore: updated the template and documentation * docs: minor update to the terraform.tfvars file * docs: minor update to the terraform.tfvars file --------- Co-authored-by: Karl Cardenas <karl@spectrocloud.com> --------- Co-authored-by: Lenny Chen <lenny.chen@spectrocloud.com> Co-authored-by: Karl Cardenas <karl@spectrocloud.com> Co-authored-by: caroldelwing <carolina.delwing@spectrocloud.com>
1 parent d36527f commit d525fc6

File tree

11 files changed

+177
-102
lines changed

11 files changed

+177
-102
lines changed

Dockerfile

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ADD static/defaults/registry-config.yml etc/spectro/config.yml
1818
ARG PALETTE_CLI_VERSION
1919
ARG PALETTE_EDGE_VERSION
2020
ARG PACKER_VERSION=1.9.4
21+
ARG ORAS_VERSION=1.0.0
2122

2223
ENV REGISTRY_LOG_LEVEL=info
2324
ENV REGISTRY_AUTH=htpasswd
@@ -29,7 +30,7 @@ COPY --from=server /etc/spectro/config.yml /etc/spectro/config.yml
2930

3031
RUN adduser -H -u 1002 -D appuser appuser && \
3132
apk update && \
32-
apk add --no-cache bash curl git terraform openssl jq bind-tools wget ca-certificates nano
33+
apk add --no-cache bash curl git terraform openssl jq bind-tools wget ca-certificates nano aws-cli xorriso govc
3334

3435
RUN wget https://software.spectrocloud.com/spectro-registry/cli/v$PALETTE_CLI_VERSION/linux/spectro && \
3536
mv spectro /usr/local/bin/spectro && \
@@ -50,13 +51,17 @@ RUN wget https://software.spectrocloud.com/spectro-registry/cli/v$PALETTE_CLI_V
5051
wget https://software.spectrocloud.com/stylus/v$PALETTE_EDGE_VERSION/cli/linux/palette-edge && \
5152
mv palette-edge /usr/local/bin/palette-edge && \
5253
chmod +x /usr/local/bin/palette-edge && \
54+
wget https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_amd64.tar.gz && \
55+
mkdir -p oras-install/ && \
56+
tar -zxf oras_${ORAS_VERSION}_*.tar.gz -C oras-install/ && \
57+
mv oras-install/oras /usr/local/bin/ && \
58+
rm -rf oras_${ORAS_VERSION}_*.tar.gz oras-install/ && \
5359
git clone https://github.com/spectrocloud/CanvOS.git && \
5460
rm -rf /var/cache/apk/*
5561

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

6267
CMD ["/bin/bash"]

docs/docker.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ The Docker image includes the following tools.
4040
| `nano` | A text editior for Unix-like computing systems or operating environments using a command line interface|
4141
| `packer` | Hashicorp Image Builder for building Edge Native images |
4242
| `GOVC` | Tool for interracting with VMware Vsphere via API |
43+
| `aws-cli` | AWS command-line interface |
44+
| `oras` | Tool for pushing and pulling OCI artifacts to and from OCI registries|
4345

4446
### Spectro Cloud Pack Registry Server
4547

@@ -63,5 +65,5 @@ If you are wanting to build the docker image locally you must provide the the bu
6365

6466

6567
```shell
66-
docker build --build-arg PALETTE_VERSION=4.0.1 --build-arg PALETTE_CLI_VERSION=4.0.1 --build-arg PALETTE_EDGE_VERSION=3.4.3 --build-arg PACKER_VERSION=1.9.4 -t tutorials .
68+
docker build --build-arg PALETTE_VERSION=4.0.2 --build-arg PALETTE_CLI_VERSION=4.0.1 --build-arg PALETTE_EDGE_VERSION=3.4.3 --build-arg PACKER_VERSION=1.9.4 -t tutorials .
6769
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
source /edge/vmware/clone_vm_template/setenv.sh
4+
5+
# Check if the packer cache exists
6+
CACHE_EXISTS=$(govc datastore.ls -ds=$vcenter_datastore /packer_cache 2>&1)
7+
8+
if [ -z "$CACHE_EXISTS" ]; then
9+
echo "Existing packer cache not found. Nothing to delete."
10+
else
11+
# Cache exists, attempt to delete it
12+
govc datastore.rm -ds=$vcenter_datastore /packer_cache
13+
RESULT=$?
14+
if [ $RESULT -eq 0 ]; then
15+
echo "Deleted previous packer cache."
16+
exit 0
17+
else
18+
echo "Failed to delete packer cache."
19+
exit 1
20+
fi
21+
fi
22+

terraform/pack-tf/README.md

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,33 @@
33
This folder contains the demo code for the [Create and Deploy a Custom Add-On Pack](https://docs.spectrocloud.com/registries-and-packs/create-pack) tutorial.
44
Use the code in this directory with the tutorial.
55

6+
7+
To get started, review the [prerequisites](#prerequisites). Next, follow the steps in the tutorial to deploy the cluster and custom add-on pack.
8+
Use the [terraform.tfvars](./terraform.tfvars) file to provide the required variables. Once you populate the variables, you can deploy the cluster and custom add-on pack.
9+
610
## Prerequisites
711
You will need the following things before getting started:
8-
1. Spectro Cloud API key generated from the Palette.
12+
1. A Palette API key.
913
2. A cloud account added to your Palette project settings.
10-
3. An SSH key created in the region where you will deploy the cluster.
11-
12-
Note that the Terraform code, when executed, will deploy the resources to the **AWS** cloud service provider.
13-
To deploy your resource to Azure or Google Cloud, use the specific layer details outlined in the **Cloud Service Provider Configurations** section below.
14+
3. An AWS Key pair or SSH key created in the region where you will deploy the cluster.
1415

16+
> [!NOTE]
17+
> This Terraform code will deploy the resources specified in the template to **AWS**.
1518
16-
## Cloud Service Provider Configurations
17-
The code uses the data resources, the core infrastructure layers, defined in the **data.tf** to deploy the `spectrocloud_cluster_profile.profile` resource to the AWS. Here are the pack details for each infrastructure layer.
1819

19-
### AWS Config
20+
## Requirements
2021

2122
| Name | Version |
2223
|------|---------|
23-
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.11.1 |
24+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 5.0 |
25+
| <a name="requirement_spectrocloud"></a> [spectrocloud](#requirement\_spectrocloud) | >= 0.16.1 |
2426

2527
## Providers
2628

2729
| Name | Version |
2830
|------|---------|
29-
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider\_spectrocloud) | >= 0.11.1 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 5.25.0 |
32+
| <a name="provider_spectrocloud"></a> [spectrocloud](#provider\_spectrocloud) | 0.16.1 |
3033

3134
## Modules
3235

@@ -38,6 +41,7 @@ No modules.
3841
|------|------|
3942
| [spectrocloud_cluster_aws.cluster](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_aws) | resource |
4043
| [spectrocloud_cluster_profile.profile](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/resources/cluster_profile) | resource |
44+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
4145
| [spectrocloud_cloudaccount_aws.account](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/cloudaccount_aws) | data source |
4246
| [spectrocloud_pack.cni](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
4347
| [spectrocloud_pack.csi](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
@@ -47,21 +51,25 @@ No modules.
4751
| [spectrocloud_pack.ubuntu](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/pack) | data source |
4852
| [spectrocloud_registry.hellouniverseregistry](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/registry) | data source |
4953
| [spectrocloud_registry.public_registry](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/registry) | data source |
54+
| [spectrocloud_registry_oci.hellouniverseregistry](https://registry.terraform.io/providers/spectrocloud/spectrocloud/latest/docs/data-sources/registry_oci) | data source |
5055

5156
## Inputs
5257

5358
| Name | Description | Type | Default | Required |
5459
|------|-------------|------|---------|:--------:|
55-
| <a name="input_aws_region_name"></a> [aws\_region\_name](#input\_aws\_region\_name) | Choose the AWS region. | `string` | n/a | yes |
56-
| <a name="input_cluster_cloud_account_aws_name"></a> [cluster\_cloud\_account\_aws\_name](#input\_cluster\_cloud\_account\_aws\_name) | Choose the AWS account integrated with Spektro Palette. | `string` | n/a | yes |
57-
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Give the cluster a name. | `string` | `"pack-tutorial-cluster"` | no |
58-
| <a name="input_cluster_profile_description"></a> [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description. | `string` | `"My cluster profile as part of the packs tutorial."` | no |
59-
| <a name="input_cluster_profile_name"></a> [cluster\_profile\_name](#input\_cluster\_profile\_name) | Give the cluster-profile a name. | `string` | `"pack-tutorial-profile"` | no |
60+
| <a name="input_aws_az_names"></a> [aws\_az\_names](#input\_aws\_az\_names) | Provide a list of AWS Availability Zones. For example: ['us-east-1a', 'us-east-1b', 'us-east-1c'] | `list(string)` | `[]` | no |
61+
| <a name="input_aws_region_name"></a> [aws\_region\_name](#input\_aws\_region\_name) | Specify the AWS region where you want to deploy the cluster. | `string` | n/a | yes |
62+
| <a name="input_cluster_cloud_account_aws_name"></a> [cluster\_cloud\_account\_aws\_name](#input\_cluster\_cloud\_account\_aws\_name) | Specify the AWS account integrated with Palette. Use the same name as the one used in the Palette project settings. | `string` | n/a | yes |
63+
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | The name of the cluster. | `string` | `"pack-tutorial-cluster"` | no |
64+
| <a name="input_cluster_profile_description"></a> [cluster\_profile\_description](#input\_cluster\_profile\_description) | Provide a description of the cluster profile. | `string` | `"My cluster profile as part of the packs tutorial."` | no |
65+
| <a name="input_cluster_profile_name"></a> [cluster\_profile\_name](#input\_cluster\_profile\_name) | The name of the cluster profile. | `string` | `"pack-tutorial-profile"` | no |
6066
| <a name="input_custom_addon_pack"></a> [custom\_addon\_pack](#input\_custom\_addon\_pack) | Custom add-on pack name. | `string` | `"hellouniverse"` | no |
6167
| <a name="input_custom_addon_pack_version"></a> [custom\_addon\_pack\_version](#input\_custom\_addon\_pack\_version) | Custom add-on pack version. | `string` | `"1.0.0"` | no |
62-
| <a name="input_private_pack_registry"></a> [private\_pack\_registry](#input\_private\_pack\_registry) | Private pack registry server name. | `string` | `"private-pack-registry"` | no |
63-
| <a name="input_ssh_key_name"></a> [ssh\_key\_name](#input\_ssh\_key\_name) | Choose the AWS region. | `string` | n/a | yes |
68+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Specify the AWS instance type. | `string` | `"m4.xlarge"` | no |
69+
| <a name="input_private_pack_registry"></a> [private\_pack\_registry](#input\_private\_pack\_registry) | The name of the private pack registry server. | `string` | n/a | yes |
70+
| <a name="input_ssh_key_name"></a> [ssh\_key\_name](#input\_ssh\_key\_name) | Specify the AWS Keypair available in the AWS region where you want to deploy the cluster. | `string` | n/a | yes |
6471
| <a name="input_tags"></a> [tags](#input\_tags) | The default tags to apply to Palette resources | `list(string)` | <pre>[<br> "spectro-cloud-education",<br> "app:hello-universe",<br> "terraform_managed:true"<br>]</pre> | no |
72+
| <a name="input_use_oci_registry"></a> [use\_oci\_registry](#input\_use\_oci\_registry) | Set the use of OCI registry to true or false. If you are not using an OCI registry, set this value to false. | `bool` | `true` | no |
6573

6674
## Outputs
6775

terraform/pack-tf/cluster.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
resource "spectrocloud_cluster_aws" "cluster" {
2-
name = var.cluster_name
3-
tags = var.tags
4-
cloud_account_id = data.spectrocloud_cloudaccount_aws.account.id
5-
depends_on = [spectrocloud_cluster_profile.profile]
2+
name = var.cluster_name
3+
tags = var.tags
4+
cloud_account_id = data.spectrocloud_cloudaccount_aws.account.id
5+
depends_on = [spectrocloud_cluster_profile.profile]
66

77
cloud_config {
8-
ssh_key_name = var.ssh_key_name
8+
ssh_key_name = var.ssh_key_name
99
region = var.aws_region_name
1010
}
11-
11+
1212
cluster_profile {
1313
id = spectrocloud_cluster_profile.profile.id
1414
}
@@ -32,9 +32,9 @@ resource "spectrocloud_cluster_aws" "cluster" {
3232
control_plane_as_worker = true
3333
name = "master-pool"
3434
count = 1
35-
instance_type = "m4.large"
35+
instance_type = var.instance_type
3636
disk_size_gb = 60
37-
azs = ["us-east-2a"]
37+
azs = local.azs
3838
}
3939

4040
##############################
@@ -48,8 +48,8 @@ resource "spectrocloud_cluster_aws" "cluster" {
4848
}
4949
name = "worker-basic"
5050
count = 1
51-
instance_type = "m5.large"
52-
azs = ["us-east-2a"]
51+
instance_type = var.instance_type
52+
azs = local.azs
5353
}
5454

5555
}

terraform/pack-tf/data.tf

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Data resources for the profile
33
####################################
44
data "spectrocloud_registry" "public_registry" {
5-
name = "Public Repo"
5+
name = "Public Repo"
66
}
77

88
####################################
@@ -12,51 +12,66 @@ data "spectrocloud_registry" "public_registry" {
1212
# Refer to the "Cloud Service Provider Configurations" section in the README for more details.
1313
####################################
1414
data "spectrocloud_pack" "ubuntu" {
15-
name = "ubuntu-aws"
16-
version = "20.04"
15+
name = "ubuntu-aws"
16+
version = "22.04"
1717
registry_uid = data.spectrocloud_registry.public_registry.id
1818
}
1919

2020
data "spectrocloud_pack" "k8s" {
21-
name = "kubernetes"
22-
version = "1.24.10"
21+
name = "kubernetes"
22+
version = "1.28.2"
2323
registry_uid = data.spectrocloud_registry.public_registry.id
2424
}
2525

2626
data "spectrocloud_pack" "cni" {
27-
name = "cni-calico"
28-
version = "3.25.0"
27+
name = "cni-calico"
28+
version = "3.26.1"
2929
registry_uid = data.spectrocloud_registry.public_registry.id
3030
}
3131

3232
data "spectrocloud_pack" "csi" {
33-
name = "csi-aws-ebs"
34-
version = "1.16.0"
33+
name = "csi-aws-ebs"
34+
version = "1.22.0"
3535
registry_uid = data.spectrocloud_registry.public_registry.id
3636
}
3737

3838
####################################
3939
# Add-On Layers
4040
####################################
4141
data "spectrocloud_pack" "spectro-proxy" {
42-
name = "spectro-proxy"
43-
version = "1.3.0"
44-
type = "spectro"
42+
name = "spectro-proxy"
43+
version = "1.4.1"
44+
type = "spectro"
45+
registry_uid = data.spectrocloud_registry.public_registry.id
4546
}
4647

48+
# Select the correct registry (OCI or non-OCI)
49+
4750
data "spectrocloud_pack" "hellouniverse" {
48-
name = var.custom_addon_pack
49-
version = var.custom_addon_pack_version
50-
registry_uid = data.spectrocloud_registry.hellouniverseregistry.id
51+
name = var.custom_addon_pack
52+
version = var.custom_addon_pack_version
53+
registry_uid = var.use_oci_registry ? data.spectrocloud_registry_oci.hellouniverseregistry[0].id : data.spectrocloud_registry.hellouniverseregistry[0].id
5154
}
5255

5356
data "spectrocloud_registry" "hellouniverseregistry" {
57+
count = var.use_oci_registry ? 0 : 1
58+
name = var.private_pack_registry
59+
}
60+
61+
data "spectrocloud_registry_oci" "hellouniverseregistry" {
62+
count = var.use_oci_registry ? 1 : 0
5463
name = var.private_pack_registry
5564
}
5665

5766
####################################
5867
# Data resources for the cluster
5968
####################################
6069
data "spectrocloud_cloudaccount_aws" "account" {
61-
name = var.cluster_cloud_account_aws_name
62-
}
70+
name = var.cluster_cloud_account_aws_name
71+
}
72+
73+
74+
####################################
75+
# AWS
76+
####################################
77+
data "aws_availability_zones" "available" {}

0 commit comments

Comments
 (0)