wip: docker and travis

This commit is contained in:
Christoph Haas 2020-11-10 11:06:04 +01:00
parent 3cbc30fe48
commit cd9abfcd5b
4 changed files with 97 additions and 3 deletions

32
.travis.yml Normal file
View File

@ -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

43
.travis/main.sh Executable file
View File

@ -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

View File

@ -4,6 +4,7 @@ MODULENAME=github.com/h44z/wg-portal
GOFILES:=$(shell go list ./... | grep -v /vendor/) GOFILES:=$(shell go list ./... | grep -v /vendor/)
BUILDDIR=dist BUILDDIR=dist
BINARIES=$(subst cmd/,,$(wildcard cmd/*)) BINARIES=$(subst cmd/,,$(wildcard cmd/*))
IMAGE=h44z/wg-portal
.PHONY: all test clean phony .PHONY: all test clean phony
@ -15,12 +16,12 @@ build: dep $(addprefix $(BUILDDIR)/,$(BINARIES))
dep: dep:
$(GOCMD) mod download $(GOCMD) mod download
validate: validate: dep
$(GOCMD) fmt $(GOFILES) $(GOCMD) fmt $(GOFILES)
$(GOCMD) vet $(GOFILES) $(GOCMD) vet $(GOFILES)
$(GOCMD) test -race $(GOFILES) $(GOCMD) test -race $(GOFILES)
coverage: coverage: dep
$(GOCMD) fmt $(GOFILES) $(GOCMD) fmt $(GOFILES)
$(GOCMD) test $(GOFILES) -v -coverprofile .testCoverage.txt $(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+\%) $(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 coverage-html: coverage
$(GOCMD) tool cover -html=.testCoverage.txt $(GOCMD) tool cover -html=.testCoverage.txt
test: test: dep
$(GOCMD) test $(MODULENAME)/... -v -count=1 $(GOCMD) test $(MODULENAME)/... -v -count=1
clean: clean:
@ -36,5 +37,11 @@ clean:
rm -rf .testCoverage.txt rm -rf .testCoverage.txt
rm -rf $(BUILDDIR) rm -rf $(BUILDDIR)
docker-build:
docker build -t $(IMAGE) .
docker-push:
docker push $(IMAGE)
$(BUILDDIR)/%: cmd/%/main.go dep phony $(BUILDDIR)/%: cmd/%/main.go dep phony
$(GOCMD) build -o $@ $< $(GOCMD) build -o $@ $<

12
docker-compose.yml Normal file
View File

@ -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