Skip to content

Commit

Permalink
Add acceptance tests and documentation for Kong API gateway plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Sep 30, 2024
1 parent 5c2492c commit bf347d0
Show file tree
Hide file tree
Showing 13 changed files with 655 additions and 3 deletions.
113 changes: 113 additions & 0 deletions .web-docs/components/provisioner/kong-api-gateway/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
Include a short description about the provisioner. This is a good place
to call out what the provisioner does, and any additional text that might
be helpful to a user. See https://www.packer.io/docs/provisioner/null
-->

The `kong-api-gateway` provisioner is used to install [Kong API gateway] server in AWS AMI image

hashistack deploys Kong API Gateway in the following way:

- Deploys the gateway in **HTTP** mode
- Deploys a reverse proxy Nginx in front of the gateway in the same EC2 to redirect all HTTPS request to
gateway's [corresponding][Kong gateway - various ports] HTTP ports

The diagrams below illustrates the resulting deployment

![Error loading kong-deployment-diagram.png](img/kong-deployment-diagram.png)

<!-- Provisioner Configuration Fields -->

**Required**

- `sonatypeNexusRepositoryDomain` (string) - the SSL-enabled domain that will serve the deployed HTTP Nexus instance.
- `sslCertBase64` (string) - is a __base64 encoded__ string of the content of
[SSL certificate file](https://hashistack.org/docs/setup#optional-setup-ssl) for the SSL-enabled domain, for
example `nexus.mycompany.com` given the `sonatypeNexusRepositoryDomain` is `nexus.mycompany.com`.
- `sslCertKeyBase64` (string) - is a __base64 encoded__ string of the content of
[SSL certificate key file](https://hashistack.org/docs/setup#optional-setup-ssl) for the SSL-enabled domain, for
example `nexus.mycompany.com` given the `sonatypeNexusRepositoryDomain` is `nexus.mycompany.com`.

<!--
Optional Configuration Fields
Configuration options that are not required or have reasonable defaults
should be listed under the optionals section. Defaults values should be
noted in the description of the field
-->

**Optional**

- `homeDir` (string) - The `$Home` directory in AMI image; default to `/home/ubuntu`

<!--
A basic example on the usage of the provisioner. Multiple examples
can be provided to highlight various configurations.
-->

### Example Usage

```hcl
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
}
}
source "amazon-ebs" "hashistack" {
ami_name = "packer-plugin-hashistack-acc-test-ami"
force_deregister = "true"
force_delete_snapshot = "true"
instance_type = "t2.micro"
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = 8
volume_type = "gp2"
delete_on_termination = true
}
region = "us-west-1"
source_ami_filter {
filters = {
name = "ubuntu/images/*ubuntu-*-22.04-amd64-server-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["099720109477"]
}
ssh_username = "ubuntu"
}
build {
sources = [
"source.amazon-ebs.hashistack"
]
provisioner "hashistack-sonatype-nexus-repository-provisioner" {
homeDir = "/home/ubuntu"
sslCertBase64 = "YXNkZnNnaHRkeWhyZXJ3ZGZydGV3ZHNmZ3RoeTY0cmV3ZGZyZWd0cmV3d2ZyZw=="
sslCertKeyBase64 = "MzI0NXRnZjk4dmJoIGNsO2VbNDM1MHRdzszNDM1b2l0cmo="
sonatypeNexusRepositoryDomain = "nexus.mycompany.com"
}
}
```

[AWS AMI]: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html
[AWS EC2 instance type]: https://aws.amazon.com/ec2/instance-types/
[AWS regions]: https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html#Concepts.RegionsAndAvailabilityZones.Availability
[AWS Security Group]: https://docs.aws.amazon.com/vpc/latest/userguide/vpc-security-groups.html

[hashistack/hashicorp/kong-api-gateway/images]: https://github.com/QubitPi/hashistack/tree/master/hashicorp/kong-api-gateway/images
[hashistack/hashicorp/kong-api-gateway/instances]: https://github.com/QubitPi/hashistack/tree/master/hashicorp/kong-api-gateway/instances
[HashiCorp Packer - Install]: https://packer.qubitpi.org/packer/install
[HashiCorp Packer variable values file]: https://packer.qubitpi.org/packer/guides/hcl/variables#from-a-file
[HashiCorp Terraform - Install]: https://terraform.qubitpi.org/terraform/install
[HashiCorp Terraform variable values file]: https://terraform.qubitpi.org/terraform/language/values/variables#variable-definitions-tfvars-files

[Kong API Gateway]: https://qubitpi.github.io/docs.konghq.com/gateway/latest/
[Kong manager UI]: https://qubitpi.github.io/docs.konghq.com/gateway/latest/kong-manager/
[Kong gateway - various ports]: https://qubitpi.github.io/docs.konghq.com/gateway/latest/production/networking/default-ports/
40 changes: 40 additions & 0 deletions docs/provisioners/img/kong-deployment-diagram.drawio
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<mxfile host="app.diagrams.net" modified="2024-01-22T14:07:20.072Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" etag="_PlwtMFcjjGP0QxHQZTX" version="22.1.21" type="device">
<diagram name="Page-1" id="VUl8XLlqUB6xemB4lQbv">
<mxGraphModel dx="2483" dy="1033" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0" />
<mxCell id="1" parent="0" />
<mxCell id="DJQC2RDwO1SS9-1ErAOI-1" value="" style="shape=image;verticalLabelPosition=bottom;labelBackgroundColor=default;verticalAlign=top;aspect=fixed;imageAspect=0;image=https://docs.konghq.com/assets/images/products/gateway/getting-started-guide/route-and-service.png;" vertex="1" parent="1">
<mxGeometry x="-160" y="240" width="1200" height="266" as="geometry" />
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-2" value="" style="rounded=0;whiteSpace=wrap;html=1;strokeColor=none;" vertex="1" parent="1">
<mxGeometry x="-110" y="400" width="120" height="60" as="geometry" />
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-3" value="&lt;font size=&quot;1&quot; style=&quot;&quot; face=&quot;Ubuntu&quot;&gt;&lt;b style=&quot;font-size: 25px;&quot;&gt;Nginx&lt;/b&gt;&lt;/font&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="-90" y="407.5" width="80" height="45" as="geometry" />
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-4" value="&lt;font size=&quot;1&quot; style=&quot;&quot; face=&quot;Ubuntu&quot;&gt;&lt;b style=&quot;font-size: 25px;&quot;&gt;HTTP&lt;/b&gt;&lt;/font&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="90" y="407.5" width="80" height="45" as="geometry" />
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-5" value="" style="endArrow=classic;html=1;rounded=0;strokeWidth=3;strokeColor=#808080;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="-340" y="400" as="sourcePoint" />
<mxPoint x="-180" y="400" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-6" value="" style="endArrow=classic;html=1;rounded=0;strokeWidth=3;strokeColor=#808080;" edge="1" parent="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="-180" y="460" as="sourcePoint" />
<mxPoint x="-340" y="460" as="targetPoint" />
</mxGeometry>
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-7" value="&lt;font size=&quot;1&quot; style=&quot;&quot; face=&quot;Ubuntu&quot;&gt;&lt;b style=&quot;font-size: 25px;&quot;&gt;HTTPS&lt;/b&gt;&lt;/font&gt;" style="text;html=1;strokeColor=none;fillColor=none;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;" vertex="1" parent="1">
<mxGeometry x="-300" y="407.5" width="80" height="45" as="geometry" />
</mxCell>
<mxCell id="DJQC2RDwO1SS9-1ErAOI-9" value="&lt;font style=&quot;font-size: 30px;&quot; face=&quot;Ubuntu&quot;&gt;&lt;b&gt;EC2 Instance&lt;/b&gt;&lt;/font&gt;" style="points=[[0,0],[0.25,0],[0.5,0],[0.75,0],[1,0],[1,0.25],[1,0.5],[1,0.75],[1,1],[0.75,1],[0.5,1],[0.25,1],[0,1],[0,0.75],[0,0.5],[0,0.25]];outlineConnect=0;gradientColor=none;html=1;whiteSpace=wrap;fontSize=12;fontStyle=0;container=1;pointerEvents=0;collapsible=0;recursiveResize=0;shape=mxgraph.aws4.group;grIcon=mxgraph.aws4.group_ec2_instance_contents;strokeColor=#D86613;fillColor=none;verticalAlign=top;align=left;spacingLeft=30;fontColor=#D86613;dashed=0;strokeWidth=4;" vertex="1" parent="1">
<mxGeometry x="-210" y="180" width="910" height="360" as="geometry" />
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit bf347d0

Please sign in to comment.