Skip to content

Added new dynamic-ubuntu-wait.sh #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ jobs:
- checkout
- run: docker-compose up shellcheck

integration_test:
docker:
- image: 087285199408.dkr.ecr.us-east-1.amazonaws.com/circle-ci-test-image-base:go1.14
steps:
- checkout
- run:
name: run tests
command: |
mkdir -p /tmp/logs
run-go-tests --path integration-test --timeout 2h | tee /tmp/logs/all.log
no_output_timeout: 3600s
- run:
command: terratest_log_parser --testlog /tmp/logs/all.log --outputdir /tmp/logs
when: always
- store_artifacts:
path: /tmp/logs
- store_test_results:
path: /tmp/logs

bats_ubuntu1604:
# We need to run Docker Compose with privileged settings, which isn't supported by CircleCI's Docker executor, so
# we have to use the machine executor instead.
Expand All @@ -27,5 +46,7 @@ workflows:
checks:
jobs:
- shellcheck
- integration_test:
context: Gruntwork Admin
- bats_ubuntu1604
- bats_ubuntu1804
8 changes: 3 additions & 5 deletions Dockerfile.shellcheck
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM bash:3.2

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

ARG SHELLCHECK_VERSION=stable
ARG SHELLCHECK_VERSION=v0.7.1
ARG SHELLCHECK_FORMAT=gcc

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

CMD ["bash"]
CMD ["bash"]
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ elif os_is_centos; then
fi
```




## Install

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

#### Example of `dynamic-ubuntu-wait.sh` usage:

You can use the `dynamic-ubuntu-wait.sh` command after you [install bash-commons](#install):

```
bash /opt/gruntwork/bash-commons/dynamic-ubuntu-wait.sh
```

Alternatively, you can call the script without installing by curling it during your existing provisioning/automated installation process:

```bash
curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/[VERSION]/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash`
```

Where `[VERSION]` could be: `v0.0.3`. The latest release can be found [here](https://github.com/gruntwork-io/bash-commons/releases/latest)




## Importing modules
Expand Down Expand Up @@ -115,6 +129,9 @@ Here's an overview of the modules available in `bash-commons`:
logic, whereas all the direct calls to the AWS CLI and EC2 metadata endpoints are delegated to `aws.sh` to make unit
testing easier.

* `dynamic-ubuntu-wait.sh`: A script that dynamically waits for Ubuntu automatic update mechanism to
release all locks so that `apt-get` may run without errors.

* `file.sh`: A collection of helpers for working with files, such as checking if a file exists or contains certain text.

* `log.sh`: A collection of logging helpers that write logs to `stderr` with log levels (INFO, WARN, ERROR) and
Expand All @@ -125,8 +142,7 @@ Here's an overview of the modules available in `bash-commons`:

* `string.sh`: A collection of string manipulation functions, such as checking if a string contains specific text,
stripping prefixes, and stripping suffixes.





## Coding principles
Expand Down
41 changes: 41 additions & 0 deletions examples/dynamic-ubuntu-wait/packer-build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"min_packer_version": "0.12.0",
"variables": {
"aws_region": "us-west-1",
"instance_type": "",
"module_branch": ""
},
"builders": [{
"name": "dynamic-wait-test-ami-ubuntu",
"ami_name": "gruntwork-ubuntu-dynamic-wait-example-{{uuid | clean_resource_name}}",
"ami_description": "An Ubuntu AMI that has Elasticsearch installed.",
"instance_type": "{{user `instance_type`}}",
"region": "{{user `aws_region`}}",
"type": "amazon-ebs",
"source_ami_filter": {
"filters": {
"virtualization-type": "hvm",
"architecture": "x86_64",
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
"block-device-mapping.volume-type": "gp2",
"root-device-type": "ebs"
},
"owners": ["099720109477"],
"most_recent": true
},
"ssh_username": "ubuntu"
}],
"provisioners": [{
"type": "shell",
"inline": [
"# Get around issue where automatic ubuntu updates prevent package installation.",
"curl -LsS https://raw.githubusercontent.com/gruntwork-io/bash-commons/{{user `module_branch`}}/modules/bash-commons/src/dynamic-ubuntu-wait.sh | bash",
"sudo apt-get -y update"
]
},{
"type": "shell",
"inline": [
"sudo DEBIAN_FRONTEND=noninteractive apt-get install -y rolldice"
]
}]
}
26 changes: 26 additions & 0 deletions integration-test/dynamic_ubuntu_wait_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package integration_test

import (
"testing"

"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/git"
"github.com/gruntwork-io/terratest/modules/packer"
)

func TestDynamicUbuntuWait(t *testing.T) {
t.Parallel()

region := aws.GetRandomStableRegion(t, nil, nil)
instance_type := aws.GetRecommendedInstanceType(t, region, []string{"t2.micro", "t3.micro"})
buildOptions := &packer.Options{
Template: "../examples/dynamic-ubuntu-wait/packer-build.json",
Vars: map[string]string{
"aws_region": region,
"instance_type": instance_type,
"module_branch": git.GetCurrentBranchName(t),
},
}
artifactID := packer.BuildArtifact(t, buildOptions)
aws.DeleteAmiAndAllSnapshots(t, region, artifactID)
}
5 changes: 5 additions & 0 deletions integration-test/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/gruntwork-io/bash-commons/integration-test

go 1.14

require github.com/gruntwork-io/terratest v0.29.0
Loading