From 92847fc3b77ddff7a007e1e99accc42a2eed86ac Mon Sep 17 00:00:00 2001 From: Noah Petherbridge Date: Thu, 28 Feb 2019 18:32:44 -0800 Subject: [PATCH] Docker Build Scripts for Debian and Ubuntu --- .gitignore | 3 +++ Makefile | 25 +++++++++++++++++++++++-- docker/Debian.dockerfile | 23 +++++++++++++++++++++++ docker/Ubuntu.dockerfile | 23 +++++++++++++++++++++++ docker/dist-debian.sh | 10 ++++++++++ docker/dist-ubuntu.sh | 10 ++++++++++ pkg/wallpaper/wallpaper_test.go | 2 +- 7 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 docker/Debian.dockerfile create mode 100644 docker/Ubuntu.dockerfile create mode 100755 docker/dist-debian.sh create mode 100755 docker/dist-ubuntu.sh diff --git a/.gitignore b/.gitignore index 8fbafa8..627c24c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ fonts/ maps/ bin/ +dist/ +docker/ubuntu +docker/debian screenshot-*.png map-*.json pkg/wallpaper/*.png diff --git a/Makefile b/Makefile index 2f08226..9c41c1d 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ SHELL := /bin/bash -VERSION=$(shell grep -e 'Version' doodle.go | head -n 1 | cut -d '"' -f 2) +VERSION=$(shell grep -e 'Version =' doodle.go | head -n 1 | cut -d '"' -f 2) BUILD=$(shell git describe --always) CURDIR=$(shell curdir) @@ -10,7 +10,7 @@ LDFLAGS := -ldflags "-X main.Build=$(BUILD)" # `make setup` to set up a new environment, pull dependencies, etc. .PHONY: setup setup: clean - go get -u ./... + go get ./... # `make build` to build the binary. .PHONY: build @@ -34,6 +34,27 @@ guitest: test: go test ./... +# `make dist` builds and tars up a release. +.PHONY: dist +dist: build + mkdir -p dist/doodle-$(VERSION) + cp bin/* dist/doodle-$(VERSION)/ + cp -r assets fonts README.md Changes.md dist/doodle-$(VERSION)/ + cd dist && tar -czvf doodle-$(VERSION).tar.gz doodle-$(VERSION) + cd dist && zip -r doodle-$(VERSION).zip doodle-$(VERSION) + +# `make docker` to run the Docker builds +.PHONY: docker docker.ubuntu docker.debian __docker.dist +docker.ubuntu: + mkdir -p docker/ubuntu + ./docker/dist-ubuntu.sh +docker.debian: + mkdir -p docker/debian + ./docker/dist-debian.sh +docker: docker.ubuntu docker.debian +__docker.dist: dist + cp dist/*.tar.gz dist/*.zip /mnt/export/ + # `make clean` cleans everything up. .PHONY: clean clean: diff --git a/docker/Debian.dockerfile b/docker/Debian.dockerfile new file mode 100644 index 0000000..2316a59 --- /dev/null +++ b/docker/Debian.dockerfile @@ -0,0 +1,23 @@ +FROM debian:latest +MAINTAINER Noah Petherbridge +ENV GOPATH /home/builder/go + +RUN apt update && apt -y upgrade && \ + apt -y install git zip golang \ + libsdl2-dev libsdl2-ttf-dev make && \ + apt clean + +# Create a user to build the packages. +RUN useradd builder -u 1000 -m -G users && \ + echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Add the project to the GOPATH +ADD . /home/builder/go/src/git.kirsle.net/apps/doodle +RUN chown -R builder:builder /home/builder/go + +# Build the app +USER builder +WORKDIR /home/builder/go/src/git.kirsle.net/apps/doodle +RUN make setup +RUN make dist +CMD ["make", "__docker.dist"] diff --git a/docker/Ubuntu.dockerfile b/docker/Ubuntu.dockerfile new file mode 100644 index 0000000..af25c0f --- /dev/null +++ b/docker/Ubuntu.dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:latest +MAINTAINER Noah Petherbridge +ENV GOPATH /home/builder/go + +RUN apt update && apt -y upgrade && \ + apt -y install git zip golang \ + libsdl2-dev libsdl2-ttf-dev make && \ + apt clean + +# Create a user to build the packages. +RUN useradd builder -u 1000 -m -G users && \ + echo "builder ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers + +# Add the project to the GOPATH +ADD . /home/builder/go/src/git.kirsle.net/apps/doodle +RUN chown -R builder:builder /home/builder/go + +# Build the app +USER builder +WORKDIR /home/builder/go/src/git.kirsle.net/apps/doodle +RUN make setup +RUN make dist +CMD ["make", "__docker.dist"] diff --git a/docker/dist-debian.sh b/docker/dist-debian.sh new file mode 100755 index 0000000..3500802 --- /dev/null +++ b/docker/dist-debian.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Run this script from the root of the repo. +if [[ ! -f "./docker/dist-debian.sh" ]]; then + echo "Run this script from the root of the doodle repo, i.e.: ./docker/dist-debian.sh" + exit 1 +fi + +sudo docker build -t doodle_debian -f ./docker/Debian.dockerfile . +sudo docker run --rm -v "$(pwd)/docker/debian:/mnt/export:z" doodle_debian diff --git a/docker/dist-ubuntu.sh b/docker/dist-ubuntu.sh new file mode 100755 index 0000000..b920257 --- /dev/null +++ b/docker/dist-ubuntu.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Run this script from the root of the repo. +if [[ ! -f "./docker/dist-ubuntu.sh" ]]; then + echo "Run this script from the root of the doodle repo, i.e.: ./docker/dist-ubuntu.sh" + exit 1 +fi + +sudo docker build -t doodle_ubuntu -f ./docker/Ubuntu.dockerfile . +sudo docker run --rm -v "$(pwd)/docker/ubuntu:/mnt/export:z" doodle_ubuntu diff --git a/pkg/wallpaper/wallpaper_test.go b/pkg/wallpaper/wallpaper_test.go index 72d3c1e..4efcecf 100644 --- a/pkg/wallpaper/wallpaper_test.go +++ b/pkg/wallpaper/wallpaper_test.go @@ -28,7 +28,7 @@ func TestWallpaper(t *testing.T) { img := image.NewRGBA(image.Rect(0, 0, width, height)) draw.Draw( // Corner: red - img, // dst Image + img, // dst Image image.Rect(0, 0, qWidth, qHeight), // r Rectangle image.NewUniform(red), // src Image image.Point{0, 0}, // sp Point