Skip to content

Commit

Permalink
Moved Docker setup into Dockerfile (#1)
Browse files Browse the repository at this point in the history
To make local testing easier.
  • Loading branch information
freemanjp committed Aug 18, 2016
1 parent 5f7d2a0 commit fc1865b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
34 changes: 15 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,31 @@ services:
- docker

before_install:
# Create the docker container
- sudo docker run --detach --volume $(pwd):/ansible/ansible-role-java --name test_dkr ubuntu:16.04 /sbin/init
# Create the Docker image
- sudo docker build --rm --file=tests/Dockerfile --tag=test_img tests

# Install dependencies
- sudo docker exec test_dkr apt-get -qq update
- sudo docker exec test_dkr apt-get -qq -y install ansible
- sudo docker exec test_dkr apt-get -qq -y install sudo
# Verify test user
- sudo docker run --rm --user=test_usr test_img sudo ansible --version

# Verify dependencies installed
- sudo docker exec test_dkr ansible --version
- sudo docker exec test_dkr sudo -V
script:
# Assign the name of the current directory as the repo_name
- 'repo_name=${PWD##*/}'

# Configure test user
- sudo docker exec test_dkr useradd --home /home/test_usr test_usr
- sudo docker exec test_dkr bash -c "echo 'test_usr ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/test_usr"
# Create the Docker container
- sudo docker run --detach --volume=$(pwd):/ansible/$repo_name --name=test_dkr test_img /sbin/init

# Verify test user
- sudo docker exec --user test_usr test_dkr sudo ansible --version
# Save Docker exec command to an environment variable
- 'exec_dkr="sudo docker exec --user=test_usr test_dkr"'

script:
# Basic role syntax check
- 'sudo docker exec --user test_usr --tty test_dkr bash -c "cd /ansible/ansible-role-java && ansible-playbook -i tests/inventory --syntax-check tests/test.yml"'
- '$exec_dkr bash -c "cd /ansible/$repo_name && ansible-playbook -i tests/inventory --syntax-check tests/test.yml"'

# Run the playbook with ansible-playbook
- 'sudo docker exec --user test_usr --tty test_dkr bash -c "cd /ansible/ansible-role-java && ansible-playbook -i tests/inventory tests/test.yml"'
- '$exec_dkr bash -c "cd /ansible/$repo_name && ansible-playbook -i tests/inventory tests/test.yml"'

# Check the Java is installed
- 'sudo docker exec --user test_usr --tty test_dkr bash -c "source /etc/profile && java -version"'
- 'sudo docker exec --user test_usr --tty test_dkr bash -c "source /etc/profile && javac -version"'
- '$exec_dkr bash -c "source /etc/profile && java -version"'
- '$exec_dkr bash -c "source /etc/profile && javac -version"'

# Clean up
- sudo docker stop test_dkr
Expand Down
20 changes: 20 additions & 0 deletions tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:16.04

# Update apt
RUN apt-get -qq update

# Install sudo
RUN apt-get -qq -y install sudo
RUN sudo -V

# Install ansible
RUN apt-get -qq -y install ansible

# Configure test user
RUN useradd --home /home/test_usr test_usr
RUN bash -c "echo 'test_usr ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/test_usr"
RUN mkdir -p /home/test_usr/.ansible/tmp
RUN chown root:root /home
RUN chmod 'u=rwx,go=rx' /home
RUN chown -R test_usr:test_usr /home/test_usr
RUN chmod -R 'u=rwx,go=rx' /home/test_usr

0 comments on commit fc1865b

Please sign in to comment.