Skip to content

Commit

Permalink
Fixed it so the CI build UI
Browse files Browse the repository at this point in the history
The UI stopped getting build by the CI. Updated the
workflow files to build the UI and upload it as an
artifact that people can use.

* Improved version command to contain additional version
information about the binary.
* Imporved the workflow to reduce amount of duplicated work
* include branch name as part of version information.

fixes #855
  • Loading branch information
gdey committed May 26, 2022
1 parent 2e53a65 commit ebdaddb
Show file tree
Hide file tree
Showing 11 changed files with 16,595 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_pr_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
go install -mod=vendor github.com/mattn/goveralls
$(go env GOPATH)/bin/goveralls -coverprofile=profile.cov -service=github
- name: Build embeded UI
- name: Build embedded UI
run: |
pushd ${GITHUB_WORKSPACE}/server
go generate ./...
Expand Down
107 changes: 83 additions & 24 deletions .github/workflows/on_release_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ jobs:
- name: Check out code
uses: actions/checkout@v2

# on release we want to use release.tag_name for the version
# on release, we want to use release.tag_name for the version
- name: Set tegola version (use release.tag_name)
if: github.event_name == 'release'
run: echo ${{ github.event.release.tag_name }} > ${{ github.workspace }}/version.txt

# when it's not a release build use the commit hash for the version tag
- name: Set tegola version (use commit hash)
- name: Set Tegola version (use commit hash)
if: github.event_name != 'release'
run: echo ${{ github.sha }} | cut -c1-7 > ${{ github.workspace }}/version.txt

Expand All @@ -31,7 +31,7 @@ jobs:
name: version
path: ${{ github.workspace }}/version.txt

# when it's not a release but we want to perform an action on a new push/pr to default branch
# when it's not a release, but we want to perform an action on a new push/pr to default branch
# we need the default branch ref, which in case of tegola changes with the version
- name: Get tegola default branch ref
run: |
Expand All @@ -45,9 +45,34 @@ jobs:
name: default-branch-ref
path: ${{ github.workspace }}/default-branch-ref.txt

build_ui:
name: Build for embedded ui
runs-on: ubuntu-20.04

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Build embedded UI
run: |
pushd ${GITHUB_WORKSPACE}/server
go generate ./...
popd
- name: Upload build artifact version
uses: actions/upload-artifact@v2
with:
name: ui
path: ${{ github.workspace }}/ui/dist

build_linux:
name: Build for Linux and AWS Lambda
needs: gen_version
needs: [gen_version,build_ui]
runs-on: ubuntu-20.04

steps:
Expand All @@ -59,21 +84,30 @@ jobs:
with:
name: version

- name: Set tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
- name: Download ui artifact
uses: actions/download-artifact@v1
with:
name: ui
path: ${{ github.workspace }}/ui/dist

- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Set tegola version
run: |
go run ci/cat_version_envs.go -version_file version/version.txt >> $GITHUB_ENV
- name: Build for Linux
env:
# build architecture
GOOS: linux
run: |
ls ui/dist
cd cmd/tegola
go build -mod vendor -ldflags "-w -X github.com/go-spatial/tegola/cmd/tegola/cmd.Version=${VERSION}"
go build -mod vendor -ldflags "-w -X github.com/go-spatial/tegola/internal/build.Version=${VERSION} -X github.com/go-spatial/tegola/internal/build.GitRevision=${GIT_REVISION} -X github.com/go-spatial/tegola/internal/build.GitBranch=${GIT_BRANCH}"
# workaround for archives losing permissions
# https://github.com/actions/upload-artifact/issues/38
Expand Down Expand Up @@ -114,7 +148,8 @@ jobs:
name: version

- name: Set tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
run: |
go run ci/cat_version_envs.go -version_file version/version.txt >> $GITHUB_ENV
- name: Build tegola_lambda
uses: ./.github/actions/amazon-linux-build-action
Expand Down Expand Up @@ -147,7 +182,7 @@ jobs:

build_macos:
name: Build for MacOS
needs: gen_version
needs: [gen_version,build_ui]
runs-on: macos-latest

steps:
Expand All @@ -159,22 +194,30 @@ jobs:
with:
name: version

- name: Set Tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
- name: Download ui artifact
uses: actions/download-artifact@v1
with:
name: ui
path: ${{ github.workspace }}/ui/dist

- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v2
with:
go-version: 1.16
go-version: 1.18

- name: Set tegola version
run: |
go run ci/cat_version_envs.go -version_file version/version.txt >> $GITHUB_ENV
- name: Build for Darwin
env:
GOOS: darwin
run: |
cd cmd/tegola
go build -mod vendor -ldflags "-w -X github.com/go-spatial/tegola/internal/build.Version=${VERSION}"
go build -mod vendor -ldflags "-w -X github.com/go-spatial/tegola/internal/build.Version=${VERSION} -X github.com/go-spatial/tegola/internal/build.GitRevision=${GIT_REVISION} -X github.com/go-spatial/tegola/internal/build.GitBranch=${GIT_BRANCH}"
# workaround for archives losing permissions
# workaround for archives losing permissions
# https://github.com/actions/upload-artifact/issues/38
- name: Zip archive permissions workaround
run: |
Expand All @@ -200,7 +243,7 @@ jobs:

build_docker:
name: Build Docker image and publish to Docker Hub
needs: gen_version
needs: [gen_version,build_ui]
runs-on: ubuntu-20.04
env:
DOCKERHUB_ORG: gospatial
Expand All @@ -215,20 +258,29 @@ jobs:
with:
name: version

- name: Download ui artifact
uses: actions/download-artifact@v1
with:
name: ui
path: ${{ github.workspace }}/ui/dist

- name: Download default-branch-ref artifact
uses: actions/download-artifact@v1
with:
name: default-branch-ref

- name: Set tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
run: |
echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
echo "GIT_BRANCH=$(git branch --no-color --show-current)" >> $GITHUB_ENV
echo "GIT_REVISION=$(git log HEAD --oneline | head -n 1 | cut -d ' ' -f 1)" >> $GITHUB_ENV
- name: Set tegola default branch ref
run: echo "DEFAULT_BRANCH_REF=$(cat default-branch-ref/default-branch-ref.txt)" >> $GITHUB_ENV

- name: Build and tag Docker container
run: |
docker build -t tegola --build-arg VERSION=${VERSION} .
docker build -t tegola --build-arg VERSION=${VERSION} --build-arg GIT_BRANCH=${GIT_BRANCH} --build-arg GIT_REVISION=${GIT_REVISION} .
docker tag tegola:latest ${DOCKERHUB_ORG}/${DOCKERHUB_REPO}:${VERSION}
docker tag tegola:latest ${DOCKERHUB_ORG}/${DOCKERHUB_REPO}:latest
docker tag tegola:latest ${DOCKERHUB_ORG}/${DOCKERHUB_REPO}:edge
Expand All @@ -254,7 +306,7 @@ jobs:
build_windows:
name: Build for Windows
needs: gen_version
needs: [gen_version,build_ui]
runs-on: windows-latest

steps:
Expand All @@ -266,18 +318,25 @@ jobs:
with:
name: version

- name: Set tegola version
run: echo "VERSION=$(cat version/version.txt)" >> $GITHUB_ENV
- name: Download ui artifact
uses: actions/download-artifact@v1
with:
name: ui
path: ${{ github.workspace }}/ui/dist

- name: Set up Go 1.16
- name: Set up Go 1.18
uses: actions/setup-go@v1
with:
go-version: 1.16
go-version: 1.18

- name: Set tegola version
run: |
go run ci/cat_version_envs.go -version_file version/version.txt >> $Env:GITHUB_ENV
- name: Build for Windows
run: |
cd cmd\tegola
go build -ldflags "-w -X github.com/go-spatial/tegola/cmd/tegola/cmd.Version=$Env:VERSION"
go build -ldflags "-w -X github.com/go-spatial/tegola/internal/build.Version=$Env:VERSION -X github.com/go-spatial/tegola/internal/build.GitRevision=$Env:GIT_REVISION -X github.com/go-spatial/tegola/internal/build.GitBranch=$Env:GIT_BRANCH"
- name: Upload build artifacts
uses: actions/upload-artifact@v1
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ If you just need to play with the binary the easy way is to get the binary from

If however you want to build the latest release candidate you will have to build from source. The first thing to do is to clone the `go-spatial/tegola` repo to your `GOPATH`. The simplest way to do this is to use `go get -u github.com/go-spatial/tegola`, navigate to the repository root then:

* Checkout the current release candidate branch, (i.e. v0.7.0)
* Checkout the current release candidate branch, (i.e. v0.15.0)

(`git checkout v0.7.0`)
(`git checkout v0.15.0`)

* Create a new feature branch.

Expand Down
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@
FROM golang:1.16.2-alpine3.12 AS build

ARG VERSION="Version Not Set"
ARG GIT_BRANCH="not set"
ARG GIT_REVISION="not set"
ENV VERSION="${VERSION}"
ENV GIT_BRANCH="${GIT_BRANCH}"
ENV GIT_REVISION="${GIT_REVISION}"
ENV BUILD_PKG=github.com/go-spatial/tegola/internal/build

# Only needed for CGO support at time of build, results in no noticable change in binary size
# incurs approximately 1:30 extra build time (1:54 vs 0:27) to install packages. Doesn't impact
# development as these layers are drawn from cache after the first build.
RUN apk update \
RUN apk update \
&& apk add musl-dev=1.1.24-r10 \
&& apk add gcc=9.3.0-r2

Expand All @@ -45,7 +50,10 @@ COPY . /go/src/github.com/go-spatial/tegola

# Build binary
RUN cd /go/src/github.com/go-spatial/tegola/cmd/tegola \
&& go build -v -ldflags "-w -X 'github.com/go-spatial/tegola/cmd/tegola/cmd.Version=${VERSION}'" -gcflags "-N -l" -o /opt/tegola \
&& go build -v \
-ldflags "-w -X '${BUILD_PKG}.Version=${VERSION}' -X '${BUILD_PKG}.GitRevision=${GitRevision}' -X '${BUILD_PKG}.GitBranch=${GitBranch}'" \
-gcflags "-N -l" \
-o /opt/tegola \
&& chmod a+x /opt/tegola

# Create minimal deployment image, just alpine & the binary
Expand Down
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ name = "zoning" # used in the URL to reference this
max_zoom = 18 # maximum zoom level to include this layer
```

\* more on PostgreSQL SSL mode [here](https://www.postgresql.org/docs/9.2/static/libpq-ssl.html). The `postgis` config also supports "ssl_cert" and "ssl_key" options are required, corresponding semantically with "PGSSLKEY" and "PGSSLCERT". These options do not check for environment variables automatically. See the section [below](#environment-variables) on injecting environment variables into the config.

More information on PostgreSQL SSL modes can be found [here](https://www.postgresql.org/docs/9.2/static/libpq-ssl.html).
The `postgis` config also supports _"ssl_key"_ and _"ssl_cert"_ options are required, corresponding semantically with
_"PGSSLKEY"_ and _"PGSSLCERT"_. These options do not check for environment variables automatically.

See the section [below](#environment-variables) on injecting environment variables into the config.

### Example config using Postgres 12 / PostGIS 3.0 ST_AsMVT():

Expand Down Expand Up @@ -287,13 +292,17 @@ The requested tile will be encoded with a layer that has the `name` value set to

## Building from source

Tegola is written in [Go](https://golang.org/) and requires Go 1.16 to compile from the source. (We support the two newest versions of Go.) To build tegola from the source, make sure you have Go installed and have cloned the repository. Navigate to the repository then run the following command:

Tegola is written in [Go](https://golang.org/) and requires [Go 1.17](https://go.dev/dl/) or higher to compile from the source.
(We support the two newest versions of Go.)
To build tegola from the source, make sure you have Go installed and have cloned the repository.
Navigate to the repository then run the following command:

```bash
cd cmd/tegola/ && go build -mod vendor
go generate ... && cd cmd/tegola/ && go build -mod vendor
```

You will now have a binary named `tegola` in the current directory which is [ready to run.](#running-tegola-as-a-vector-tile-server).
You will now have a binary named `tegola` in the current directory which is [ready to run](#running-tegola-as-a-vector-tile-server).

**Build Flags**
The following build flags can be used to turn off certain features of tegola:
Expand All @@ -313,10 +322,24 @@ Example of using the build flags to turn of the Redis cache back end, the GeoPac
go build -tags 'noRedisCache noGpkgProvider noViewer'
```

**Setting Version Information** The following flags can be used to set version information:

```bash
# first set some env to make it easier to read:
BUILD_PKG=github.com/go-spatial/tegola/internal/build
VERSION=1.15.x
GIT_BRANCH=$(git branch --no-color --show-current)
GIT_REVISION=$(git log HEAD --oneline | head -n 1 | cut -d ' ' -f 1)

# build the go binary
go build -ldflags "-w -X ${BUILD_PKG}.Version=${VERSION} -X ${BUILD_PKG}.GitRevision=${GIT_REVISION} -X ${BUILD_PKG}.GitBranch=${GIT_BRANCH}"
```

## License

See [license](LICENSE.md) file in the repo.

## Looking for a vector tile style editor?

After Tegola is running you're likely going to want to work on your map's cartography. Give [fresco](https://github.com/go-spatial/fresco) a try!
After Tegola is running you're likely going to want to work on your map's cartography.
Give [fresco](https://github.com/go-spatial/fresco) a try!
Loading

0 comments on commit ebdaddb

Please sign in to comment.