Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
BertrandGouny committed Dec 16, 2015
1 parent 69fa13b commit 6eb9c22
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/.twgit_features_subject
/.twgit
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## 0.1.0
- Initial release
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
NAME = osixia/tinc
VERSION = 0.1.0

.PHONY: all build build-nocache test tag_latest release

all: build

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

build-nocache:
docker build -t $(NAME):$(VERSION) --no-cache --rm image

test:
env NAME=$(NAME) VERSION=$(VERSION) bats test/test.bats

tag_latest:
docker tag -f $(NAME):$(VERSION) $(NAME):latest

release: build test tag_latest
@if ! docker images $(NAME) | awk '{ print $$2 }' | grep -q -F $(VERSION); then echo "$(NAME) version $(VERSION) is not yet built. Please run 'make build'"; false; fi
docker push $(NAME)
@echo "*** Don't forget to run 'twgit release/hotfix finish' :)"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# osixia/tinc
29 changes: 29 additions & 0 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM osixia/experimental-light-baseimage:0.1.0
MAINTAINER Bertrand Gouny <[email protected]>

# Use baseimage's init system.
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/run
CMD ["/container/tool/run"]

# Install OpenLDAP, ldap-utils and ssl-helper from baseimage and remove default ldap db
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/install-service-available
RUN echo "deb http://http.debian.net/debian experimental main" >> /etc/apt/sources.list && apt-get -y update \
&& LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
-t experimental tinc

# Add service directory to /container/service
ADD service /container/service

# Use baseimage install-service script and clean all
# https://github.com/osixia/docker-light-baseimage/blob/stable/image/tool/install-service
RUN /container/tool/install-service \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Add default env variables
ADD env.yaml /container/environment/env.yaml

# Set tinc config directory in a data volume
VOLUME ["/etc/tinc"]

EXPOSE 655/tcp 655/udp
7 changes: 7 additions & 0 deletions image/env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TINC_HOSTNAME: test_example_org

TINC_RUN_BEFORE_START_COMMANDS:
- add Address = 1.1.1.1
- add Subnet = 10.244.1.0/24
- add Mode = switch
- add DeviceType = tap
20 changes: 20 additions & 0 deletions image/service/tinc/container-start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash -ex

FIRST_START_DONE="/etc/docker-tinc-first-start-done"

# container first start
if [ ! -e "$FIRST_START_DONE" ]; then

/usr/sbin/tinc init $TINC_HOSTNAME

# add root user on specified networks
TINC_RUN_BEFORE_START_COMMANDS=($TINC_RUN_BEFORE_START_COMMANDS)
for command in "${TINC_RUN_BEFORE_START_COMMANDS[@]}"
do
echo "Run tinc command: ${!command}"
/usr/sbin/tinc ${!command}
done

fi

exit 0
2 changes: 2 additions & 0 deletions image/service/tinc/daemon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash -e
exec /usr/sbin/tinc start -D
9 changes: 9 additions & 0 deletions test/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bats
load test_helper

@test "image build" {

run build_image
[ "$status" -eq 0 ]

}
111 changes: 111 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
setup() {
IMAGE_NAME="$NAME:$VERSION"
}

# function relative to the current container / image
build_image() {
#disable outputs
docker build -t $IMAGE_NAME $BATS_TEST_DIRNAME/../image &> /dev/null
}

run_image() {
CONTAINER_ID=$(docker run $@ -d $IMAGE_NAME)
CONTAINER_IP=$(get_container_ip_by_cid $CONTAINER_ID)
}

start_container() {
start_containers_by_cid $CONTAINER_ID
}

stop_container() {
stop_containers_by_cid $CONTAINER_ID
}

remove_container() {
remove_containers_by_cid $CONTAINER_ID
}

clear_container() {
stop_containers_by_cid $CONTAINER_ID
remove_containers_by_cid $CONTAINER_ID
}

is_service_running() {
is_service_running_by_cid $CONTAINER_ID $1
}

is_file_exists() {
is_file_exists_by_cid $CONTAINER_ID $1
}

wait_service() {
wait_service_by_cid $CONTAINER_ID $@
}


# generic functions
get_container_ip_by_cid() {
local IP=$(docker inspect -f "{{ .NetworkSettings.IPAddress }}" $1)
echo "$IP"
}

start_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker start $cid &> /dev/null
done
}

stop_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker stop $cid &> /dev/null
done
}

remove_containers_by_cid() {
for cid in "$@"
do
#disable outputs
docker rm $cid &> /dev/null
done
}

clear_containers_by_cid() {
stop_containers_by_cid $@
remove_containers_by_cid $@
}

is_service_running_by_cid() {
docker exec $1 ps cax | grep $2 > /dev/null
}

is_file_exists_by_cid() {
docker exec $1 cat "/etc/my_init_startup_files_completed" > /dev/null 2>&1
}

wait_service_by_cid() {

cid=$1

sleep 1

# first wait image init end
while ! is_file_exists_by_cid $cid /etc/my_init_startup_files_completed
do
sleep 1
done

for service in "${@:2}"
do
# wait service
while ! is_service_running_by_cid $cid $service
do
sleep 1
done
done

sleep 5
}

0 comments on commit 6eb9c22

Please sign in to comment.