Skip to content

Commit

Permalink
Add support for Docker image build
Browse files Browse the repository at this point in the history
  • Loading branch information
tsandall committed Oct 18, 2016
1 parent 17af66f commit 4dfa7ac
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 83 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
vendor
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@

# build artifacts
coverage
opa
opa_linux_amd64
opa_darwin_amd64
opa_*
.Dockerfile_*

# runtime artifacts
policies
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
language: go
env:
- CROSSCOMPILE="linux/amd64 darwin/amd64"
go:
- 1.6
- 1.7
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2016 The OPA Authors. All rights reserved.
# Use of this source code is governed by an Apache2
# license that can be found in the LICENSE file.

FROM scratch

MAINTAINER Torin Sandall <[email protected]>

ADD /opa_linux_GOARCH /opa

ENTRYPOINT ["/opa"]

CMD ["run"]
32 changes: 19 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Use of this source code is governed by an Apache2
# license that can be found in the LICENSE file.

VERSION := "0.1.1-dev"
VERSION := 0.1.1-dev

PACKAGES := \
github.com/open-policy-agent/opa/ast/.../ \
Expand All @@ -16,6 +16,13 @@ PACKAGES := \
github.com/open-policy-agent/opa/test/.../

GO := go
GOARCH := $(shell go env GOARCH)
GOOS := $(shell go env GOOS)

BIN := opa_$(GOOS)_$(GOARCH)

REPOSITORY := openpolicyagent
IMAGE := $(REPOSITORY)/opa

BUILD_COMMIT := $(shell ./build/get-build-commit.sh)
BUILD_TIMESTAMP := $(shell ./build/get-build-timestamp.sh)
Expand All @@ -26,10 +33,6 @@ LDFLAGS := "-X github.com/open-policy-agent/opa/version.Version=$(VERSION) \
-X github.com/open-policy-agent/opa/version.Timestamp=$(BUILD_TIMESTAMP) \
-X github.com/open-policy-agent/opa/version.Hostname=$(BUILD_HOSTNAME)"

# Set CROSSCOMPILE to space separated list of <platform>/<arch> pairs to
# have the build produce binaries for each platform/arch.
CROSSCOMPILE ?=

GO15VENDOREXPERIMENT := 1
export GO15VENDOREXPERIMENT

Expand All @@ -46,11 +49,15 @@ generate:
$(GO) generate

build: generate
ifeq ($(CROSSCOMPILE),)
$(GO) build -o opa -ldflags $(LDFLAGS)
else
@./build/cross-compile.sh --prefix opa --ldflags $(LDFLAGS) --platforms "$(CROSSCOMPILE)"
endif
$(GO) build -o $(BIN) -ldflags $(LDFLAGS)

image:
@$(MAKE) build GOOS=linux
sed -e 's/GOARCH/$(GOARCH)/g' Dockerfile.in > .Dockerfile_$(GOARCH)
docker build -t $(IMAGE):$(VERSION) -f .Dockerfile_$(GOARCH) .

push:
docker push $(IMAGE):$(VERSION)

install: generate
$(GO) install -ldflags $(LDFLAGS)
Expand Down Expand Up @@ -87,6 +94,5 @@ fmt:
$(GO) fmt $(PACKAGES)

clean:
rm -f ./opa
rm -f ./opa_linux_amd64
rm -f ./opa_darwin_amd64
rm -f opa_*_*
rm -f .Dockerfile_*
61 changes: 0 additions & 61 deletions build/cross-compile.sh

This file was deleted.

21 changes: 17 additions & 4 deletions docs/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,31 @@ CHANGELOG.md snippet and uploading the packages from the build phase.
git checkout v<semver>
```

1. Run command to build packages. This will produce a bunch of binaries (e.g., amd64/linux, i386/linux, amd64/darwin, etc.) that can be published (“distributions”).
1. Build binaries for target platforms.

```
make build CROSSCOMPILE="linux/amd64 darwin/amd64"
make build GOOS=linux GOARCH=amd64
make build GOOS=darwin GOARCH=amd64
```

1. Build Docker image.

```
make image
```
## Publishing
1. Open browser and go to https://github.com/open-policy-agent/opa/releases
1. Create a new release for the version.
- Copy the changelog content into the message.
- Upload the distributions packages.
- Upload the binaries.
1. Push the Docker image.
```
make push
```
1. In addition to publishing the packages, there may be documentation updates that should be released. See [site/README.md](../site/README.md) for steps to update the website.
1. There may be documentation updates that should be released. See [site/README.md](../site/README.md) for steps to update the website.

0 comments on commit 4dfa7ac

Please sign in to comment.