Skip to content

Commit

Permalink
Adding the ability to develop Gorson completely in Docker. (#19)
Browse files Browse the repository at this point in the history
* Adding the ability to develop Gorson completely in Docker.

* adding a docker compose file too

* updated docker docs to show docker-compose too

* fixing typo
  • Loading branch information
joshfinnie authored and cmac1000 committed Nov 26, 2019
1 parent 34c9fcd commit 4ee92dd
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM golang:1.13.4-alpine

# borrowed with gratitude from confd
# https://github.com/kelseyhightower/confd/blob/master/Dockerfile.build.alpine?at=09f6676

WORKDIR /app
RUN apk add --no-cache bash gcc git musl-dev

COPY go.mod /app/go.mod
COPY go.sum /app/go.sum
RUN go mod download
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: '3'
services:
builder:
build: .
volumes:
- .:/app
40 changes: 40 additions & 0 deletions docs/docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Setting up Docker

This repository has been built with development of `gorson` done entirely in Docker in mind. Below are the steps required to get
this package up and running through Docker.

## Build Docker image

```bash
$ docker build -t gorson .
```

or

```bash
$ docker-compose build
```

## Run tests on Docker image

```bash
$ docker run -it -v `pwd`:/app gorson ./scripts/test.sh
```

or

```bash
$ docker-compose run --rm builder ./scripts/test.sh
```

## Create releases

```bash
$ docker run -it -v `pwd`:/app gorson ./scripts/docker-release.sh
```

or

```bash
$ docker-compose run --rm builder ./scripts/docker-release.sh
```
34 changes: 34 additions & 0 deletions scripts/docker-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'

# tooling logic borrowed heavily from the talented minds of confd
# https://github.com/kelseyhightower/confd/blob/master/Makefile

cd "$( dirname "${BASH_SOURCE[0]}" )/.."

./scripts/clean.sh
mkdir -p bin

VERSION=`egrep -o '[0-9]+\.[0-9a-z.\-]+' ./internal/gorson/version/version.go`

# We want to make sure the final builds are formatted and linted properly.
./scripts/format.sh
./scripts/lint.sh

# for each of our target platforms we use the gorson_builder
# docker container to compile a binary of our application
>&2 echo "compiling binaries for release"
for platform in darwin linux; do \
binary_name="gorson-${VERSION}-${platform}-amd64"
>&2 echo "compiling $binary_name"

# * GOOS is the target operating system
# * GOARCH is the target processor architecture
# (we only compile for amd64 systems)
# see https://golang.org/cmd/go/#hdr-Environment_variables
# * CGO_ENABLED controls whether the go compiler allows us to
# import C packages (we don't do this, so we set it to 0 to turn CGO off)
# see https://golang.org/cmd/cgo/
GOOS=$platform GOARCH=amd64 CGO_ENABLED=0 go build -o bin/$binary_name
done

0 comments on commit 4ee92dd

Please sign in to comment.