Skip to content

Commit

Permalink
Merge pull request #32 from kingsoftcloud/trunk
Browse files Browse the repository at this point in the history
Trunk
  • Loading branch information
notone0010 authored Aug 7, 2023
2 parents 2123936 + 9048a56 commit 27c44b1
Show file tree
Hide file tree
Showing 30 changed files with 1,493 additions and 137 deletions.
90 changes: 90 additions & 0 deletions .docs/builders/epc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
---
description: >
The ksyun-epc Packer builder is able to create Ksyun Images backed by
bare metal instance storage as the root device.
page_title: Ksyun EPC - Builders
nav_title: Epc
---

# Ksyun Image Builder (epc)

Type: `ksyun-epc`

The `ksyun-epc` Packer builder is able to create Ksyun Images backed by
bare metal instance storage as the root device.


## Configuration Reference

There are many configuration options available for the builder. In addition to
the items listed here, you will want to look at the general configuration
references for [Image](#image-configuration),
[Access](#access-configuration),
[Run](#run-configuration) and
[General](#general-configuration)
configuration references, which are
necessary for this build to succeed and can be found further down the page.

## Run Configuration
### Required:

@include 'builder/epc/KsyunEpcRunConfig-required.mdx'

### Optional:

@include 'builder/epc/KsyunEpcRunConfig-not-required.mdx'

## Access Configuration

### Required:

@include 'builder/AccessConfig-required.mdx'

## General Configuration

### Optional:

@include 'builder/CommonConfig-not-required.mdx'

## Image Configuration

### Optional:

@include 'builder/epc/KsyunImageConfig-not-required.mdx'

## Basic Example

Here is a basic example. It is completely valid but excludes the access keys:

### Example Usage

```json
{
"variables": {
"access_key": "{{ env `KSYUN_ACCESS_KEY` }}",
"secret_key": "{{ env `KSYUN_SECRET_KEY` }}"
},
"builders": [{
"type":"ksyun-epc",
"access_key":"{{user `access_key`}}",
"secret_key":"{{user `secret_key`}}",
"region":"cn-beijing-6",
"source_image_id":"eb8c0428-476e-49af-8ccb-9fad2455a54c",
"host_type":"EC-I-III-II",
"availability_zone":"cn-beijing-6c",
"raid": "Raid1",
"ssh_username":"root",
"ssh_clear_authorized_keys": true,
"associate_public_ip_address": true
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"yum install mysql -y"
]
}]
}

```
135 changes: 135 additions & 0 deletions .docs/builders/kec.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
description: >
The ksyun-kec Packer builder is able to create Ksyun Images backed by
instance storage as the root device.
page_title: Ksyun Instance(KEC) - Builders
nav_title: Instance(KEC)
---

# Ksyun Image Builder (kec)

Type: `ksyun-kec`

The `ksyun-kec` Packer builder is able to create Ksyun Images backed by
instance storage as the root device.


## Configuration Reference

There are many configuration options available for the builder. In addition to
the items listed here, you will want to look at the general configuration
references for [Image](#image-configuration),
[Access](#access-configuration),
[Run](#run-configuration) and
[General](#general-configuration)
configuration references, which are
necessary for this build to succeed and can be found further down the page.

## Run Configuration

### Required:

@include 'builder/kec/KsyunKecRunConfig-required.mdx'

### Optional:

@include 'builder/kec/KsyunKecRunConfig-not-required.mdx'

## Access Configuration

### Required:

@include 'builder/AccessConfig-required.mdx'

## General Configuration

### Optional:

@include 'builder/CommonConfig-not-required.mdx'

## Image Configuration

### Required:

@include 'builder/kec/KsyunImageConfig-required.mdx'

### Optional:

@include 'builder/kec/KsyunImageConfig-not-required.mdx'

### Source Image Filter Configuration

@include 'builder/KmiFilterOptions-not-required.mdx'

## Basic Example

Here is a basic example. It is completely valid but excludes the access keys:

### Example Usage

```hcl
packer {
required_plugins {
ksyun = {
version = ">=0.1.0"
source = "github.com/kingsoftcloud/ksyun"
}
}
}
variable ak {
type = string
default = "${env("KSYUN_ACCESS_KEY")}"
}
variable sk {
type = string
default = "${env("KSYUN_SECRET_KEY")}"
}
source "ksyun-kec" "test" {
access_key = var.ak
secret_key = var.sk
region = "cn-shanghai-2"
image_name = "packer_test"
source_image_id = "IMG-05f198b3-9df6-4f94-a3e3-dcee4b48c4aa"
instance_type = "N3.1B"
ssh_username = "root"
# 此参数用于跳过ssh
# communicator = "none"
# 如需使用ssh,须保证网络能通,如果不在同一个网络环境下就要挂公网ip
associate_public_ip_address = true
ssh_clear_authorized_keys = true
# 此参数为true时,data_disks的硬盘不会打快照加入镜像
image_ignore_data_disks = true
data_disks {
data_disk_type = "SSD3.0"
data_disk_size = 50
}
# 复制镜像到以下region
image_copy_regions = ["cn-beijing-6", "cn-guangzhou-1"]
# 镜像复制后的名称, 不命名则使用原镜像的名称
image_copy_names = ["copy-test"]
# 开启镜像预热
image_warm_up = true
# 镜像共享给其他用户
# image_share_accounts = ["xxxxxxxx", "xxxxxxxx"]
}
build {
sources = ["source.ksyun-kec.test"]
provisioner "shell" {
inline = ["sleep 10", "df -h"]
}
}
```
99 changes: 99 additions & 0 deletions .docs/datasources/kmi.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
description: >
The Ksyun KMI data source provides information from a KMI that will be fetched based
on the filter options provided in the configuration.
page_title: Ksyun KMI - Data Source
nav_title: Ksyun KMI
---

# Ksyun KMI Data Source

Type: `ksyun-kmi`

The Ksyun KMI data source will filter and fetch a Ksyun Images, and output all the Ksyun Machine images information that will
be then available to use in the [Ksyun builders](./).

-> **Note:** Data sources is a feature exclusively available to HCL2 templates.

Basic example of usage:

```hcl
data "ksyun-kmi" "foo" {
access_key = "ksyun access key"
secret_key = "ksyun secret key"
region = "cn-shanghai-2"
platform = "centos-7.5"
name_regex = "centos-7.5.*"
image_source = "system" // import, copy, share, extend, system.
most_recent = true
}
```
This selects the most recent Centos 7.5 Ksyun Images from remote Ksyun. Note that the data source will fail unless
*exactly* one AMI is returned. In the above example, `most_recent` will cause this to succeed by selecting the newest image.

## Configuration Reference

### Required:

@include 'builder/AccessConfig-required.mdx'

### Optional:

@include 'builder/KmiFilterOptions-not-required.mdx'

## Output Data

@include 'datasource/kmi/DatasourceOutput.mdx'

## Basic Example

Here is a basic example. It is completely valid but excludes the access keys:

### Example Usage

```hcl
packer {
required_plugins {
ksyun = {
version = ">=0.1.0"
source = "github.com/kingsoftcloud/ksyun"
}
}
}
variable ak {
type = string
default = "${env("KSYUN_ACCESS_KEY")}"
}
variable sk {
type = string
default = "${env("KSYUN_SECRET_KEY")}"
}
data "ksyun-kmi" "foo" {
access_key = var.ak
secret_key = var.sk
region = "cn-shanghai-2"
platform = "centos-7.5"
name_regex = "centos-7.5.*"
image_source = "system" // import, copy, share, extend, system.
most_recent = true
}
source "ksyun-kec" "test" {
access_key = var.ak
secret_key = var.sk
region = "cn-shanghai-2"
image_name = "packer_test"
source_image_id = data.ksyun-kmi.foo.id
instance_type = "N3.1B"
ssh_username = "root"
}
build {
sources = ["source.ksyun-kec.test"]
}
```
11 changes: 9 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ before:
# this is just an example and not a requirement for provider building/publishing
- go mod tidy
- go mod vendor
# As part of the release doc files are included as a separate deliverable for
# consumption by Packer.io. To include a separate docs.zip uncomment the following command.
- make ci-release-docs
builds:
- env:
# goreleaser does not work with CGO, it could also complicate
Expand Down Expand Up @@ -51,7 +54,11 @@ signs:
- "--detach-sign"
- "${artifact}"
release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
# As part of the release doc files are included as a separate deliverable for consumption by Packer.io.
# To include a separate docs.zip uncomment the extra_files config and the docs.zip command hook above.
extra_files:
- glob: ./docs.zip
changelog:
skip: true
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ test_integration:
install-packer-sdc: ## Install packer sofware development command
go install github.com/hashicorp/packer-plugin-sdk/cmd/packer-sdc@${HASHICORP_PACKER_PLUGIN_SDK_VERSION}

ci-release-docs: install-packer-sdc
@/bin/sh -c "if [ -d docs ]; then echo \"removed existed docs directory\" && rm -rf docs; fi"
@packer-sdc renderdocs -src .docs -partials docs-partials/ -dst docs/
@/bin/sh -c "[ -d docs ] && zip -r docs.zip docs/"

lint:
go vet .
Expand All @@ -26,7 +30,5 @@ install: build

generate: install-packer-sdc
go generate ./...
packer-sdc renderdocs -src ./docs -dst ./.docs -partials ./docs-partials


.PHONY: default test test_integration lint build install
6 changes: 4 additions & 2 deletions builder/common_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ type CommonConfig struct {
// the primary IP address of the instance. Only one can be selected and bound to the primary network card.
// If this parameter is not specified, the system will automatically select one from the valid address pool at random
// Valid values: standard IP address format
PrivateIpAddress string `mapstructure:"private_ip_address" required:"false"`
AssociatePublicIpAddress bool `mapstructure:"associate_public_ip_address" required:"false"`
PrivateIpAddress string `mapstructure:"private_ip_address" required:"false"`
// Indicating associate whether public ip for creating kec instance
// Default `false`
AssociatePublicIpAddress bool `mapstructure:"associate_public_ip_address" required:"false"`
// PublicIp charge type, which can be
// Daily TrafficMonthly DailyPaidByTransfer HourlyInstantSettlement
// Default is Daily
Expand Down
Loading

0 comments on commit 27c44b1

Please sign in to comment.