Skip to content

Commit

Permalink
Merge pull request #1552 from chef/jsnapp/IPACK-31-make-it-easy-to-re…
Browse files Browse the repository at this point in the history
…produce-verify-pipeline-builds-locally

Make it easy to reproduce verify pipeline builds locally
  • Loading branch information
tas50 committed Jan 20, 2022
2 parents 09ca9a4 + c08b3d8 commit 7f7d35a
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
.bundle
Gemfile.lock
pkg/*
test/pkg/*
/binstubs
/bin

Expand Down
13 changes: 0 additions & 13 deletions Dockerfile
@@ -1,16 +1,3 @@
FROM chefes/releng-base

ARG SOFTWARE
ARG VERSION

COPY ./ /omnibus-software
COPY ./test /test

WORKDIR /test

RUN curl -L https://omnitruck.chef.io/install.sh | bash -s -- -P omnibus-toolchain

RUN . /opt/omnibus-toolchain/bin/load-omnibus-toolchain \
&& DEBUG=1 bundle config set --local without development \
&& DEBUG=1 bundle install \
&& bundle exec omnibus build test
28 changes: 25 additions & 3 deletions README.md
Expand Up @@ -30,14 +30,36 @@ This repository is versioned and tagged using the `YY.MM.BUILD` to allow folks t

For information on contributing to this project please see our [Contributing Documentation](https://github.com/chef/chef/blob/main/CONTRIBUTING.md)

### Testing via Docker
### Testing On Ubuntu 18.04 via Docker

We provide a sample Dockerfile you can use to ensure that your software definitions are able to compile on Ubuntu 18.04.
#### Interactive Testing

If you want to enter an interactive shell in a dockerized omnibus build environment on Ubuntu 18.04 you can run the following command.

```
bundle exec rake test_build <SOFTWARE> (<VERSION>)
docker-compose run --rm -e SOFTWARE=<SOFTWARE> -e VERSION=<VERSION> builder
```

Now you should be in a shell in the container ready to explore, modify or build.

You can start the build by running the following command in your shell.

```
bundle exec omnibus build test
```

The container will automatically be destroyed when you exit it without requiring any further cleanup.

#### Non-Interactive Testing

If you only want to run a build without an interactive shell you can set the `CI` environment variable as you see in the following command.

```
docker-compose run --rm -e SOFTWARE=<SOFTWARE> -e VERSION=<VERSION> -e CI=true builder
```

The container will automatically be destroyed when you exit it without requiring any further cleanup.

## License & Copyright

- Copyright:: Copyright (c) 2012-2021 Chef Software, Inc.
Expand Down
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -27,9 +27,9 @@ task :test_build do

raise "\nERROR: You must specify a software name\n\n" if software.nil?

command = "docker build --build-arg SOFTWARE=#{software}"
command += " --build-arg VERSION=#{version}" unless version == "default"
command += " --tag localhost:5000/omnibus-#{software}:#{version} ."
command = "docker-compose run --rm -e CI=true -e SOFTWARE=#{software}"
command += " -e VERSION=#{version}" unless version == "default"
command += " builder"

sh command
end
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,15 @@
services:
builder:
build: .
volumes:
- ./:/omnibus-software
- ./test:/test
working_dir: /test
command: bash --init-file omnibus-build.sh

# Multiple concurrent "docker-compose run" commands on the same system in the CI pipeline caused intermittent failures
# while creating the network.
# Using "network_mode: bridge" forces compose to use docker's legacy default bridge network instead.
# We considered namespacing the network using COMPOSE_PROJECT_NAME=$BUILDKITE_JOB_ID but using the legacy bridge network
# means we can avoid worrying about any impact and management overhead that multiple networks might create.
network_mode: bridge
8 changes: 7 additions & 1 deletion test/Gemfile
@@ -1,4 +1,10 @@
source "https://rubygems.org"

gem "omnibus", github: "chef/omnibus", branch: "main"
gem "omnibus-software", path: "/omnibus-software"
gem "omnibus-software", path: "/omnibus-software"

group :development do
gem "pry"
gem "pry-byebug"
gem "pry-stack_explorer"
end
2 changes: 1 addition & 1 deletion test/generate_steps.rb
Expand Up @@ -41,7 +41,7 @@ def method_missing(m, *args, &block)
$versions.compact.uniq.each do |version|
puts <<~EOH
- label: "test-build (#{software} #{version})"
command: docker build --build-arg SOFTWARE=#{software} --build-arg VERSION=#{version} .
command: docker-compose run --rm -e SOFTWARE=#{software} -e VERSION=#{version} -e CI builder
timeout_in_minutes: 30
expeditor:
executor:
Expand Down
20 changes: 20 additions & 0 deletions test/omnibus-build.sh
@@ -0,0 +1,20 @@
#!/bin/bash

# shellcheck disable=SC1090
. ~/.bashrc

# shellcheck disable=SC1091
. /opt/omnibus-toolchain/bin/load-omnibus-toolchain

if [[ $CI == true ]]; then
DEBUG=1 bundle config set --local without development
fi

rm -f Gemfile.lock

DEBUG=1 bundle install

if [[ $CI == true ]]; then
bundle exec omnibus build test
exit $?
fi

0 comments on commit 7f7d35a

Please sign in to comment.