Skip to content

Commit c580adb

Browse files
committed
Add integration test for dynamic-ubuntu-wait
1 parent 48738df commit c580adb

File tree

6 files changed

+608
-15
lines changed

6 files changed

+608
-15
lines changed

.circleci/config.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@ jobs:
66
- checkout
77
- run: docker-compose up shellcheck
88

9+
integration_test:
10+
docker:
11+
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.14
12+
steps:
13+
- checkout
14+
- run:
15+
name: run tests
16+
command: |
17+
mkdir -p /tmp/logs
18+
run-go-tests --path integration-test --timeout 2h | tee /tmp/logs/all.log
19+
no_output_timeout: 3600s
20+
- run:
21+
command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs
22+
when: always
23+
- store_artifacts:
24+
path: /tmp/logs
25+
- store_test_results:
26+
path: /tmp/logs
27+
928
bats_ubuntu1604:
1029
# We need to run Docker Compose with privileged settings, which isn't supported by CircleCI's Docker executor, so
1130
# we have to use the machine executor instead.

README.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ elif os_is_centos; then
3232
fi
3333
```
3434

35-
#### Example of `dynamic-ubuntu-wait.sh` usage:
36-
Simply call the script by curling it during your existing provisioning/automated installation process:
37-
38-
`curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/[VERSION]/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash`
39-
40-
Where `[VERSION]` could be: `v.0.0.3`. The latest release can be found [here](https://github.com/gruntwork-io/bash-commons/releases/latest)
41-
4235
## Install
4336

4437
The first step is to download the code onto your computer.
@@ -78,6 +71,23 @@ cp -r bash-commons/modules/bash-commons/src /opt/gruntwork/bash-commons
7871
sudo chown -R "my-os-username:my-os-group" /opt/gruntwork/bash-commons
7972
```
8073

74+
#### Example of `dynamic-ubuntu-wait.sh` usage:
75+
76+
You can use the `dynamic-ubuntu-wait.sh` command after you [install bash-commons](#install):
77+
78+
```
79+
bash /opt/gruntwork/bash-commons/dynamic-ubuntu-wait.sh
80+
```
81+
82+
Alternatively, you can call the script without installing by curling it during your existing provisioning/automated installation process:
83+
84+
```bash
85+
curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/[VERSION]/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash`
86+
```
87+
88+
Where `[VERSION]` could be: `v0.0.3`. The latest release can be found [here](https://github.com/gruntwork-io/bash-commons/releases/latest)
89+
90+
8191

8292

8393
## Importing modules

examples/dynamic-ubuntu-wait/packer-build.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,25 @@
22
"min_packer_version": "0.12.0",
33
"variables": {
44
"aws_region": "us-west-1",
5-
"github_auth_token": "{{env `GITHUB_OAUTH_TOKEN`}}"
5+
"instance_type": "",
6+
"module_branch": ""
67
},
78
"builders": [{
8-
"name": "elasticsearch-ami-ubuntu",
9-
"ami_name": "gruntwork-ubuntu-elasticsearch-example-{{uuid | clean_ami_name}}",
9+
"name": "dynamic-wait-test-ami-ubuntu",
10+
"ami_name": "gruntwork-ubuntu-dynamic-wait-example-{{uuid | clean_resource_name}}",
1011
"ami_description": "An Ubuntu AMI that has Elasticsearch installed.",
11-
"instance_type": "t2.micro",
12+
"instance_type": "{{user `instance_type`}}",
1213
"region": "{{user `aws_region`}}",
1314
"type": "amazon-ebs",
1415
"source_ami_filter": {
1516
"filters": {
1617
"virtualization-type": "hvm",
1718
"architecture": "x86_64",
18-
"name": "*ubuntu-xenial-16.04-amd64-server-*",
19+
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
1920
"block-device-mapping.volume-type": "gp2",
2021
"root-device-type": "ebs"
2122
},
22-
"owners": ["amazon"],
23+
"owners": ["099720109477"],
2324
"most_recent": true
2425
},
2526
"ssh_username": "ubuntu"
@@ -28,7 +29,7 @@
2829
"type": "shell",
2930
"inline": [
3031
"# Get around issue where automatic ubuntu updates prevent package installation.",
31-
"curl -Ls https://raw.githubusercontent.com/gruntwork-io/bash-commons/dynamic-ubuntu-waiter/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash",
32+
"curl -Ls https://raw.githubusercontent.com/gruntwork-io/bash-commons/{{user `module_branch`}}/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash",
3233
"sudo apt-get -y update"
3334
]
3435
},{
@@ -43,4 +44,4 @@
4344
"sudo apt-get install -y nano"
4445
]
4546
}]
46-
}
47+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package integration_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gruntwork-io/terratest/modules/aws"
7+
"github.com/gruntwork-io/terratest/modules/git"
8+
"github.com/gruntwork-io/terratest/modules/packer"
9+
)
10+
11+
func TestDynamicUbuntuWait(t *testing.T) {
12+
t.Parallel()
13+
14+
region := aws.GetRandomStableRegion(t, nil, nil)
15+
instance_type := aws.GetRecommendedInstanceType(t, region, []string{"t2.micro", "t3.micro"})
16+
buildOptions := &packer.Options{
17+
Template: "../examples/dynamic-ubuntu-wait/packer-build.json",
18+
Vars: map[string]string{
19+
"aws_region": region,
20+
"instance_type": instance_type,
21+
"module_branch": git.GetCurrentBranchName(t),
22+
},
23+
}
24+
artifactID := packer.BuildArtifact(t, buildOptions)
25+
aws.DeleteAmiAndAllSnapshots(t, region, artifactID)
26+
}

integration-test/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/gruntwork-io/bash-commons/integration-test
2+
3+
go 1.14
4+
5+
require github.com/gruntwork-io/terratest v0.29.0

0 commit comments

Comments
 (0)