Commit 261e920f authored by Chris Molozian's avatar Chris Molozian
Browse files

Add RELEASE instructions and Docker files. (#247)

parent f434f3da
Loading
Loading
Loading
Loading
+25 −11
Original line number Diff line number Diff line
# docker build . --rm --build-arg version=2.0.4 --build-arg commit=master -t heroiclabs/nakama:2.0.4
## Copyright 2018 The Nakama Authors
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http:##www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

# docker build "$PWD" --build-arg commit=d79ccd1 --build-arg version=v2.1.0 -t heroiclabs/nakama:2.1.0

FROM golang:1.11.1-alpine3.7 as builder

ARG commit
ARG version

RUN apk --no-cache add ca-certificates gcc musl-dev git
ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 1

WORKDIR /go/src/github.com/heroiclabs/
RUN git config --global advice.detachedHead false && \
  git clone -q -n https://github.com/heroiclabs/nakama
RUN apk --no-cache add ca-certificates gcc musl-dev git && \
    git config --global advice.detachedHead false && \
    git clone --quiet --no-checkout https://github.com/heroiclabs/nakama /go/src/github.com/heroiclabs/nakama

WORKDIR /go/src/github.com/heroiclabs/nakama
RUN git checkout -q "$commit" && \
  GOOS=linux GOARCH=amd64 go build && \
  mkdir -p /go/build && \
  mv nakama /go/build
RUN git checkout --quiet "$commit" && \
    go build -o /go/build/nakama -gcflags "-trimpath $PWD" -asmflags "-trimpath $PWD" -ldflags "-s -w -X main.version=$version -X main.commitID=$commit"

FROM alpine:3.7

@@ -37,4 +52,3 @@ ENTRYPOINT ["./nakama"]

HEALTHCHECK --interval=5m --timeout=3s \
  CMD curl -f http://localhost:7350/ || exit 1

build/README.md

0 → 100644
+87 −0
Original line number Diff line number Diff line
Release Instructions
===

These instructions guide the release process for new official Nakama server builds.

## Steps

To build releases for a variety of platforms we use the excellent [xgo](https://github.com/karalabe/xgo) project. You will need Docker engine installed. These steps should be followed from the project root folder.

These steps are one off to install the required build utilities.

1. Install the xgo Docker image.

   ```
   docker pull karalabe/xgo-latest
   ```

2. Install the command line helper tool. Ensure "$GOPATH/bin" is on your system path to access the executable.

   ```
   env GO111MODULE=off go get -u github.com/karalabe/xgo
   ```

These steps are run for each new release.

1. Update the CHANGELOG.

2. Add the CHANGELOG file and tag a commit.

   __Note__: In source control good semver suggests a "v" prefix on a version. It helps group release tags.

   ```
   git add CHANGELOG
   git commit -m "Nakama 2.1.0 release."
   git tag -a v2.1.0 -m "v2.1.0"
   git push origin v2.1.0 master
   ```

3. Execute the cross-compiled build helper.

   ```
   xgo --targets=darwin/amd64,linux/amd64,linux/arm64,windows/amd64 --ldflags "-s -w -X main.version=2.1.0 -X main.commitID=$(git rev-parse --short HEAD 2>/dev/null)" --branch v2.1.0 github.com/heroiclabs/nakama
   ```

   This will build binaries for all target platforms supported officially by Heroic Labs.

4. Package up each release as a compressed bundle.

   ```
   tar -czf "nakama-<os>-<arch>" nakama README.md LICENSE CHANGELOG.md
   ```

5. Create a new draft release on GitHub and publish it with the compressed bundles.

## Build Nakama Image

With the release generated we can create the official container image.

1. Build the container image.

   ```
   cd build
   docker build "$PWD" --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=v2.1.0 -t heroiclabs/nakama:2.1.0
   ```

2. Push the image to the container registry.

   ```
   docker push heroiclabs/nakama:2.1.0
   ```

## Build Plugin Builder Image

With the official release image generated we can create a container image to help with Go runtime development.

1. Build the container image.

   ```
   cd build/pluginbuilder
   docker build "$PWD" --file ./Dockerfile --build-arg commit="$(git rev-parse --short HEAD 2>/dev/null)" --build-arg version=v2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0
   ```

2. Push the image to the container registry.

   ```
   docker push heroiclabs/nakama-pluginbuilder:2.1.0
   ```

build/plugin.Dockerfile

deleted100644 → 0
+0 −14
Original line number Diff line number Diff line
# docker build . --file ./build/plugin.Dockerfile --build-arg src=sample_go_module

FROM golang:1.11.1-alpine3.7 as builder

ARG src

WORKDIR /go/src/$src
COPY $src /go/src/$src

RUN apk --no-cache add ca-certificates gcc musl-dev git && \
  go get -u github.com/heroiclabs/nakama && \
  GOOS=linux go build -buildmode=plugin . && \
  mkdir -p /go/build && \
  mv "/go/src/$src/$src.so" /go/build/
+39 −0
Original line number Diff line number Diff line
## Copyright 2018 The Nakama Authors
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http:##www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.

# docker build "$PWD" --file ./Dockerfile.pluginbuilder --build-arg commit=d79ccd1 --build-arg version=v2.1.0 -t heroiclabs/nakama-pluginbuilder:2.1.0

FROM golang:1.11.1-alpine3.7 as builder

MAINTAINER Heroic Labs <support@heroiclabs.com>

ARG commit
ARG version

LABEL version=$version
LABEL variant=nakama-pluginbuilder
LABEL description="A support container to build Go code for Nakama server's runtime."

ENV GOOS linux
ENV GOARCH amd64
ENV CGO_ENABLED 1

RUN apk --no-cache add ca-certificates gcc musl-dev git && \
    git config --global advice.detachedHead false && \
    git clone --quiet --no-checkout https://github.com/heroiclabs/nakama.git /go/src/github.com/heroiclabs/nakama && \
    git checkout --quiet "$commit"

WORKDIR /go/src/tempbuild/

ENTRYPOINT ["go"]