Skip to content

Commit 013a0b4

Browse files
authored
Merge pull request #4 from gruntwork-io/dynamic-ubuntu-waiter
Added new dynamic-ubuntu-wait.sh
2 parents 2af4b3a + 3a5685a commit 013a0b4

File tree

8 files changed

+681
-10
lines changed

8 files changed

+681
-10
lines changed

.circleci/config.yml

+21
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.
@@ -27,5 +46,7 @@ workflows:
2746
checks:
2847
jobs:
2948
- shellcheck
49+
- integration_test:
50+
context: Gruntwork Admin
3051
- bats_ubuntu1604
3152
- bats_ubuntu1804

Dockerfile.shellcheck

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ FROM bash:3.2
22

33
# TODO: labels here. See: http://label-schema.org/rc1/
44

5-
ARG SHELLCHECK_VERSION=stable
5+
ARG SHELLCHECK_VERSION=v0.7.1
66
ARG SHELLCHECK_FORMAT=gcc
77

88
# Install dependencies.
@@ -16,9 +16,7 @@ RUN set -e; \
1616
# Install shellcheck.
1717
RUN set -e; \
1818
mkdir -p ~/stage \
19-
&& wget "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \
20-
&& wget "https://storage.googleapis.com/shellcheck/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz.sha512sum" \
21-
&& sha512 -c shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz.sha512sum \
19+
&& wget "https://github.com/koalaman/shellcheck/releases/download/${SHELLCHECK_VERSION}/shellcheck-${SHELLCHECK_VERSION}.linux.x86_64.tar.xz" \
2220
&& tar --xz -xvf shellcheck-"${SHELLCHECK_VERSION}".linux.x86_64.tar.xz \
2321
&& cp shellcheck-"${SHELLCHECK_VERSION}"/shellcheck /usr/bin/ \
2422
&& shellcheck --version \
@@ -27,4 +25,4 @@ RUN set -e; \
2725
WORKDIR /usr/local/src/bash-commons
2826
COPY ./.circleci/ /usr/local/src/bash-commons/.circleci/
2927

30-
CMD ["bash"]
28+
CMD ["bash"]

README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ elif os_is_centos; then
3232
fi
3333
```
3434

35-
36-
37-
3835
## Install
3936

4037
The first step is to download the code onto your computer.
@@ -74,6 +71,23 @@ cp -r bash-commons/modules/bash-commons/src /opt/gruntwork/bash-commons
7471
sudo chown -R "my-os-username:my-os-group" /opt/gruntwork/bash-commons
7572
```
7673

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+
7791

7892

7993
## Importing modules
@@ -115,6 +129,9 @@ Here's an overview of the modules available in `bash-commons`:
115129
logic, whereas all the direct calls to the AWS CLI and EC2 metadata endpoints are delegated to `aws.sh` to make unit
116130
testing easier.
117131
132+
* `dynamic-ubuntu-wait.sh`: A script that dynamically waits for Ubuntu automatic update mechanism to
133+
release all locks so that `apt-get` may run without errors.
134+
118135
* `file.sh`: A collection of helpers for working with files, such as checking if a file exists or contains certain text.
119136
120137
* `log.sh`: A collection of logging helpers that write logs to `stderr` with log levels (INFO, WARN, ERROR) and
@@ -125,8 +142,7 @@ Here's an overview of the modules available in `bash-commons`:
125142
126143
* `string.sh`: A collection of string manipulation functions, such as checking if a string contains specific text,
127144
stripping prefixes, and stripping suffixes.
128-
129-
145+
130146
131147
132148
## Coding principles
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"min_packer_version": "0.12.0",
3+
"variables": {
4+
"aws_region": "us-west-1",
5+
"instance_type": "",
6+
"module_branch": ""
7+
},
8+
"builders": [{
9+
"name": "dynamic-wait-test-ami-ubuntu",
10+
"ami_name": "gruntwork-ubuntu-dynamic-wait-example-{{uuid | clean_resource_name}}",
11+
"ami_description": "An Ubuntu AMI that has Elasticsearch installed.",
12+
"instance_type": "{{user `instance_type`}}",
13+
"region": "{{user `aws_region`}}",
14+
"type": "amazon-ebs",
15+
"source_ami_filter": {
16+
"filters": {
17+
"virtualization-type": "hvm",
18+
"architecture": "x86_64",
19+
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
20+
"block-device-mapping.volume-type": "gp2",
21+
"root-device-type": "ebs"
22+
},
23+
"owners": ["099720109477"],
24+
"most_recent": true
25+
},
26+
"ssh_username": "ubuntu"
27+
}],
28+
"provisioners": [{
29+
"type": "shell",
30+
"inline": [
31+
"# Get around issue where automatic ubuntu updates prevent package installation.",
32+
"curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/{{user `module_branch`}}/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash",
33+
"sudo apt-get -y update"
34+
]
35+
},{
36+
"type": "shell",
37+
"inline": [
38+
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y rolldice"
39+
]
40+
}]
41+
}
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

+5
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)