Skip to content

Commit

Permalink
Merge pull request #527 from scrapinghub/master
Browse files Browse the repository at this point in the history
Ability to override ubuntu:18.04
  • Loading branch information
Theaxiom authored May 10, 2019
2 parents 14394bc + d616b3b commit fc6672b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ env:
- VERSION=${TRAVIS_BRANCH}

script:
- docker build -t ${NAME}:${VERSION} --rm image
- env NAME=${NAME} VERSION=${VERSION} ./test/runner.sh
- make build test

after_success:
- docker login -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}";
Expand Down
22 changes: 14 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
NAME = phusion/baseimage
VERSION = 0.11
ifdef BASE_IMAGE
BUILD_ARG = --build-arg BASE_IMAGE=$(BASE_IMAGE)
ifndef NAME
NAME = phusion/baseimage-$(subst :,-,${BASE_IMAGE})
endif
else
NAME ?= phusion/baseimage
endif
VERSION ?= 0.11


.PHONY: all build test tag_latest release ssh

all: build

build:
docker build -t $(NAME):$(VERSION) --rm image
docker build -t $(NAME):$(VERSION) $(BUILD_ARG) --rm image

test:
env NAME=$(NAME) VERSION=$(VERSION) ./test/runner.sh
Expand All @@ -19,13 +27,11 @@ release: test tag_latest
docker push $(NAME)
@echo "*** Don't forget to create a tag by creating an official GitHub release."

ssh: SSH_COMMAND?=
ssh:
chmod 600 image/services/sshd/keys/insecure_key
@ID=$$(docker ps | grep -F "$(NAME):$(VERSION)" | awk '{ print $$1 }') && \
ID=$$(docker ps | grep -F "$(NAME):$(VERSION)" | awk '{ print $$1 }') && \
if test "$$ID" = ""; then echo "Container is not running."; exit 1; fi && \
IP=$$(docker inspect $$ID | grep IPAddr | sed 's/.*: "//; s/".*//') && \
echo "SSHing into $$IP" && \
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i image/services/sshd/keys/insecure_key root@$$IP
tools/docker-ssh $$ID ${SSH_COMMAND}

test_release:
echo test_release
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,19 @@ If you want to call the resulting image something else, pass the NAME variable,

make build NAME=joe/baseimage

You can also change the `ubuntu` base-image to `debian` as these distributions are quite similar.

make build BASE_IMAGE=debian:stretch

The image will be: `phusion/baseimage-debian-stretch`. Use the `NAME` variable in combination with the `BASE_IMAGE` one to call it `joe/stretch`.

make build BASE_IMAGE=debian:stretch NAME=joe/stretch

To verify that the various services are started, when the image is run as a container, add `test` to the end of your make invocations, e.g.:

make build BASE_IMAGE=debian:stretch NAME=joe/stretch test


<a name="removing_optional_services"></a>
### Removing optional services

Expand Down
3 changes: 2 additions & 1 deletion image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM ubuntu:18.04
ARG BASE_IMAGE=ubuntu:18.04
FROM $BASE_IMAGE
MAINTAINER Phusion <[email protected]>

COPY . /bd_build
Expand Down
4 changes: 2 additions & 2 deletions image/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rm -rf /tmp/* /var/tmp/*
rm -rf /var/lib/apt/lists/*

# clean up python bytecode
find / -name *.pyc -delete
find / -name *__pycache__* -delete
find / -mount -name *.pyc -delete
find / -mount -name *__pycache__* -delete

rm -f /etc/ssh/ssh_host_*
11 changes: 10 additions & 1 deletion image/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ $minimal_apt_get_install software-properties-common
apt-get dist-upgrade -y --no-install-recommends -o Dpkg::Options::="--force-confold"

## Fix locale.
$minimal_apt_get_install language-pack-en
case $(lsb_release -is) in
Ubuntu)
$minimal_apt_get_install language-pack-en
;;
Debian)
$minimal_apt_get_install locales locales-all
;;
*)
;;
esac
locale-gen en_US
update-locale LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8
echo -n en_US.UTF-8 > /etc/container_environment/LANG
Expand Down
16 changes: 6 additions & 10 deletions test/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ function cleanup()
docker rm $ID >/dev/null
}

PWD=`pwd`

echo " --> Starting insecure container"
ID=`docker run -d -p 22 -v $PWD/test:/test $NAME:$VERSION /sbin/my_init --enable-insecure-key`
ID=`docker run -d -p 22 $NAME:$VERSION /sbin/my_init --enable-insecure-key`
sleep 1

echo " --> Obtaining SSH port number"
Expand All @@ -29,14 +27,12 @@ fi
trap cleanup EXIT

echo " --> Enabling SSH in the container"
docker exec -t -i $ID /etc/my_init.d/00_regen_ssh_host_keys.sh -f
docker exec -t -i $ID rm /etc/service/sshd/down
docker exec -t -i $ID sv start /etc/service/sshd
docker exec $ID /etc/my_init.d/00_regen_ssh_host_keys.sh -f
docker exec $ID rm /etc/service/sshd/down
docker exec $ID sv start /etc/service/sshd
sleep 1

echo " --> Logging into container and running tests"
cp image/services/sshd/keys/insecure_key /tmp/insecure_key
chmod 600 /tmp/insecure_key
sleep 1 # Give container some more time to start up.
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /tmp/insecure_key -p $SSHPORT [email protected] \
/bin/bash /test/test.sh
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
tools/docker-ssh $ID bash < test/test.sh
8 changes: 8 additions & 0 deletions tools/docker-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ fi

KNOWN_HOSTS_FILE=`mktemp /tmp/docker-ssh.XXXXXXXXX`
IP=`docker inspect -f "{{ .NetworkSettings.IPAddress }}" "$CONTAINER_ID"`
PORT=`docker inspect -f '{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}' "$CONTAINER_ID"`
if test "`uname`" = "Darwin"; then
IP="127.0.0.1"
else
PORT=22
fi
echo "SSHing into $IP:$PORT"

# Prevent SSH from warning about adding a host to the known_hosts file.
ssh-keyscan "$IP" >"$KNOWN_HOSTS_FILE" 2>&1
Expand All @@ -68,6 +75,7 @@ if ! ssh -i ~/.baseimage_docker_insecure_key \
-o PasswordAuthentication=no \
-o KbdInteractiveAuthentication=no \
-o ChallengeResponseAuthentication=no \
-p $PORT \
"root@$IP" "$@"
then
STATUS=$?
Expand Down

0 comments on commit fc6672b

Please sign in to comment.