From cd9abfcd5b38b1ef5216537d8969f4ecdb37ccf9 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Tue, 10 Nov 2020 11:06:04 +0100 Subject: [PATCH] wip: docker and travis --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ .travis/main.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ Makefile | 13 ++++++++++--- docker-compose.yml | 12 ++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 .travis.yml create mode 100755 .travis/main.sh create mode 100644 docker-compose.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9dda11e --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +# make use of vm's +sudo: 'required' + +# have the docker service set up (we'll +# update it later) +services: + - docker + +# prepare the machine before any code +# installation scripts +before_install: + - ./.travis/main.sh + + +script: + - make test + - make docker-image + + +# only execute the following instructions in +# the case of a success (failing at this point +# won't mark the build as a failure). +# To have `DOCKER_USERNAME` and `DOCKER_PASSWORD` +# filled you need to either use `travis`' cli +# and then `travis set ..` or go to the travis +# page of your repository and then change the +# environment in the settings panel. +after_success: + - if [[ "$TRAVIS_BRANCH" == "master" ]]; then + docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD ; + make docker-push ; + fi \ No newline at end of file diff --git a/.travis/main.sh b/.travis/main.sh new file mode 100755 index 0000000..3f900d8 --- /dev/null +++ b/.travis/main.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +set -o errexit + +main() { + setup_dependencies + update_docker_configuration + + echo "SUCCESS: + Done! Finished setting up travis machine. + " +} + +setup_dependencies() { + echo "INFO: + Setting up dependencies. + " + + sudo apt update -y + sudo apt install realpath python python-pip -y + sudo apt install --only-upgrade docker-ce -y + + sudo pip install docker-compose || true + + docker info + docker-compose --version +} + +update_docker_configuration() { + echo "INFO: + Updating docker configuration + " + + echo '{ + "experimental": true, + "storage-driver": "overlay2", + "max-concurrent-downloads": 50, + "max-concurrent-uploads": 50 +}' | sudo tee /etc/docker/daemon.json + sudo service docker restart +} + +main \ No newline at end of file diff --git a/Makefile b/Makefile index 0cc3161..9368cd3 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ MODULENAME=github.com/h44z/wg-portal GOFILES:=$(shell go list ./... | grep -v /vendor/) BUILDDIR=dist BINARIES=$(subst cmd/,,$(wildcard cmd/*)) +IMAGE=h44z/wg-portal .PHONY: all test clean phony @@ -15,12 +16,12 @@ build: dep $(addprefix $(BUILDDIR)/,$(BINARIES)) dep: $(GOCMD) mod download -validate: +validate: dep $(GOCMD) fmt $(GOFILES) $(GOCMD) vet $(GOFILES) $(GOCMD) test -race $(GOFILES) -coverage: +coverage: dep $(GOCMD) fmt $(GOFILES) $(GOCMD) test $(GOFILES) -v -coverprofile .testCoverage.txt $(GOCMD) tool cover -func=.testCoverage.txt # use total:\s+\(statements\)\s+(\d+.\d+\%) as Gitlab CI regextotal:\s+\(statements\)\s+(\d+.\d+\%) @@ -28,7 +29,7 @@ coverage: coverage-html: coverage $(GOCMD) tool cover -html=.testCoverage.txt -test: +test: dep $(GOCMD) test $(MODULENAME)/... -v -count=1 clean: @@ -36,5 +37,11 @@ clean: rm -rf .testCoverage.txt rm -rf $(BUILDDIR) +docker-build: + docker build -t $(IMAGE) . + +docker-push: + docker push $(IMAGE) + $(BUILDDIR)/%: cmd/%/main.go dep phony $(GOCMD) build -o $@ $< \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1e87531 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: '3.6' +services: + wg-portal: + image: h44z/wg-portal:latest + container_name: wg-portal + restart: unless-stopped + cap_add: + - NET_ADMIN + network_mode: "host" + volumes: + - /etc/wireguard:/etc/wireguard + - ./data:/app/data \ No newline at end of file