-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69fa13b
commit 6eb9c22
Showing
10 changed files
with
208 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/.twgit_features_subject | ||
/.twgit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Changelog | ||
|
||
## 0.1.0 | ||
- Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' :)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# osixia/tinc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash -e | ||
exec /usr/sbin/tinc start -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |