Skip to content

Commit

Permalink
Merge pull request #123 from JonathonReinhart/local-docker-images
Browse files Browse the repository at this point in the history
Build local docker images
  • Loading branch information
JonathonReinhart committed Sep 14, 2018
2 parents 29b14df + e8b4e2b commit b1afc42
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 23 deletions.
6 changes: 6 additions & 0 deletions ci/test_setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/sh
set -e

topdir=$(cd $(dirname $0)/.. && pwd)

# Pull this image ahead of time, so it's there for the unit tests
docker pull debian:8.2

# Build docker images for local testing
$topdir/test-docker-images/build_all.sh
7 changes: 7 additions & 0 deletions test-docker-images/build_all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
set -e
cd $(dirname $0)

entrypoint-test/build.sh
hello/build.sh
scratch/build.sh
3 changes: 3 additions & 0 deletions test-docker-images/entrypoint-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine:latest
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
6 changes: 6 additions & 0 deletions test-docker-images/entrypoint-test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e
image="scuba/entrypoint-test"
cd $(dirname $0)
docker build -t $image .
echo "Built $image"
4 changes: 4 additions & 0 deletions test-docker-images/entrypoint-test/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
export ENTRYPOINT_WORKS=success
echo 'success' > entrypoint_works.txt
exec "$@"
3 changes: 3 additions & 0 deletions test-docker-images/hello/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine
ADD hello.sh /hello.sh
CMD ["/hello.sh"]
6 changes: 6 additions & 0 deletions test-docker-images/hello/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e
image="scuba/hello"
cd $(dirname $0)
docker build -t $image .
echo "Built $image"
2 changes: 2 additions & 0 deletions test-docker-images/hello/hello.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
echo "Hello world"
4 changes: 4 additions & 0 deletions test-docker-images/scratch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM scratch

# 'docker build' complains if we don't do *something*
ADD Dockerfile /
6 changes: 6 additions & 0 deletions test-docker-images/scratch/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e
image="scuba/scratch"
cd $(dirname $0)
docker build -t $image .
echo "Built $image"
6 changes: 6 additions & 0 deletions tests/setup_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
set -e
cd $(dirname $0)
entrypoint-test/build.sh
hello/build.sh
scratch/build.sh
4 changes: 2 additions & 2 deletions tests/test_dockerutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ def test__get_image_command__pulls_image_if_missing(self):

def test_get_image_entrypoint(self):
'''get_image_entrypoint works'''
result = uut.get_image_entrypoint('jreinhart/echo')
result = uut.get_image_entrypoint('scuba/entrypoint-test')
self.assertEqual(1, len(result))
assert_str_equalish('echo', result[0])
assert_str_equalish('/entrypoint.sh', result[0])

def test_get_image_entrypoint__none(self):
'''get_image_entrypoint works for image with no entrypoint'''
Expand Down
37 changes: 16 additions & 21 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ def test_no_cmd(self):
'''Verify scuba works with no given command'''

with open('.scuba.yml', 'w') as f:
f.write('image: {}\n'.format('jreinhart/hello'))
f.write('image: {}\n'.format('scuba/hello'))

out, _ = self.run_scuba([])
self.assertTrue('Hello from alpine-hello' in out)
self.assertTrue('Hello world' in out)

def test_no_image_cmd(self):
'''Verify scuba gracefully handles an image with no Cmd and no user command'''

with open('.scuba.yml', 'w') as f:
f.write('image: {}\n'.format('jreinhart/scratch'))
f.write('image: {}\n'.format('scuba/scratch'))

# ScubaError -> exit(128)
out, _ = self.run_scuba([], 128)
Expand Down Expand Up @@ -362,39 +362,36 @@ def test_image_entrypoint(self):
'''Verify scuba doesn't interfere with the configured image ENTRYPOINT'''

with open('.scuba.yml', 'w') as f:
# This image was built with ENTRYPOINT ["echo"]
f.write('image: jreinhart/echo')
f.write('image: scuba/entrypoint-test')

out, _ = self.run_scuba(['cat', 'entrypoint_works.txt'])
assert_str_equalish('success', out)

test_string = 'Hello world'
out, _ = self.run_scuba([test_string])
assert_str_equalish(test_string, out)

def test_image_override(self):
'''Verify --image works'''

with open('.scuba.yml', 'w') as f:
# This image does not exist
f.write('image: jreinhart/notheredoesnotexistbb7e344f9722\n')
f.write('image: scuba/notheredoesnotexistbb7e344f9722\n')

test_string = 'Hello world'
args = [
# This image was built with ENTRYPOINT ["echo"]
'--image', 'jreinhart/echo',
test_string,
'--image', 'scuba/entrypoint-test',
'cat', 'entrypoint_works.txt',
]
out, _ = self.run_scuba(args)
assert_str_equalish(test_string, out)
assert_str_equalish('success', out)

def test_image_override_with_alias(self):
'''Verify --image works with aliases'''

with open('.scuba.yml', 'w') as f:
# These images do not exist
f.write('''
image: jreinhart/notheredoesnotexistbb7e344f9722
image: scuba/notheredoesnotexistbb7e344f9722
aliases:
testalias:
image: jreinhart/notheredoesnotexist765205d09dea
image: scuba/notheredoesnotexist765205d09dea
script:
- echo multi
- echo line
Expand All @@ -413,14 +410,12 @@ def test_yml_not_needed_with_image_override(self):

# no .scuba.yml

test_string = 'Hello world'
args = [
# This image was built with ENTRYPOINT ["echo"]
'--image', 'jreinhart/echo',
test_string,
'--image', 'scuba/entrypoint-test',
'cat', 'entrypoint_works.txt',
]
out, _ = self.run_scuba(args)
assert_str_equalish(test_string, out)
assert_str_equalish('success', out)

def test_complex_commands_in_alias(self):
'''Verify complex commands can be used in alias scripts'''
Expand Down

0 comments on commit b1afc42

Please sign in to comment.