Skip to content

Commit

Permalink
Enable cgo by default and disable it explicitly for docker image build (
Browse files Browse the repository at this point in the history
  • Loading branch information
alexshtin authored Jan 21, 2022
1 parent c74cb49 commit 0ff1b16
Show file tree
Hide file tree
Showing 21 changed files with 129 additions and 31 deletions.
18 changes: 10 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,26 @@ builds:
- id: "temporal-server"
dir: cmd/server
binary: temporal-server
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows
goarch:
- amd64
- arm64
- id: "temporal-server-no-cgo"
dir: cmd/server
binary: temporal-server
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
- arm64
- id: "tctl"
dir: cmd/tools/cli
binary: tctl
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
Expand All @@ -30,8 +36,6 @@ builds:
- id: "temporal-cassandra-tool"
dir: cmd/tools/cassandra
binary: temporal-cassandra-tool
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
Expand All @@ -42,8 +46,6 @@ builds:
- id: "temporal-sql-tool"
dir: cmd/tools/sql
binary: temporal-sql-tool
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR /temporal
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN make bins
RUN CGO_ENABLED=0 make bins

##### Temporal server #####
FROM ${BASE_SERVER_IMAGE} AS temporal-server
Expand Down
36 changes: 14 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ update-proto: clean-proto update-proto-submodule buf-lint api-linter protoc fix-

##### Arguments ######

GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPATH ?= $(shell go env GOPATH)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPATH ?= $(shell go env GOPATH)
CGO_ENABLED ?= $(shell go env CGO_ENABLED)

PERSISTENCE_TYPE ?= nosql
PERSISTENCE_DRIVER ?= cassandra
Expand All @@ -41,15 +42,6 @@ DOCKER_IMAGE_TAG ?= test
# Pass "registry" to automatically push image to the docker hub.
DOCKER_BUILDX_OUTPUT ?= image

# Name resolution requires cgo to be enabled on macOS and Windows: https://golang.org/pkg/net/#hdr-Name_Resolution.
ifndef CGO_ENABLED
ifeq ($(GOOS),linux)
CGO_ENABLED := 0
else
CGO_ENABLED := 1
endif
endif

ifdef TEST_TAG
override TEST_TAG := -tags $(TEST_TAG)
endif
Expand Down Expand Up @@ -191,25 +183,25 @@ clean-bins:
@rm -f temporal-sql-tool

temporal-server:
@printf $(COLOR) "Build temporal-server with OS: $(GOOS), ARCH: $(GOARCH)..."
@printf $(COLOR) "Build temporal-server with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
@./develop/scripts/create_build_info_data.sh
CGO_ENABLED=$(CGO_ENABLED) go build -o temporal-server cmd/server/main.go
go build -o temporal-server ./cmd/server

tctl:
@printf $(COLOR) "Build tctl with OS: $(GOOS), ARCH: $(GOARCH)..."
CGO_ENABLED=$(CGO_ENABLED) go build -o tctl cmd/tools/cli/main.go
@printf $(COLOR) "Build tctl with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
go build -o tctl ./cmd/tools/cli

plugins:
@printf $(COLOR) "Build tctl-authorization-plugin with OS: $(GOOS), ARCH: $(GOARCH)..."
CGO_ENABLED=$(CGO_ENABLED) go build -o tctl-authorization-plugin cmd/tools/cli/plugins/authorization/main.go
@printf $(COLOR) "Build tctl-authorization-plugin with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
go build -o tctl-authorization-plugin ./cmd/tools/cli/plugins/authorization

temporal-cassandra-tool:
@printf $(COLOR) "Build temporal-cassandra-tool with OS: $(GOOS), ARCH: $(GOARCH)..."
CGO_ENABLED=$(CGO_ENABLED) go build -o temporal-cassandra-tool cmd/tools/cassandra/main.go
@printf $(COLOR) "Build temporal-cassandra-tool with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
go build -o temporal-cassandra-tool ./cmd/tools/cassandra

temporal-sql-tool:
@printf $(COLOR) "Build temporal-sql-tool with OS: $(GOOS), ARCH: $(GOARCH)..."
CGO_ENABLED=$(CGO_ENABLED) go build -o temporal-sql-tool cmd/tools/sql/main.go
@printf $(COLOR) "Build temporal-sql-tool with CGO_ENABLED=$(CGO_ENABLED) for $(GOOS)/$(GOARCH)..."
go build -o temporal-sql-tool ./cmd/tools/sql

##### Checks #####
copyright-check:
Expand Down
31 changes: 31 additions & 0 deletions cmd/server/main_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package main

import (
_ "go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite" // needed to load sqlite plugin
)
31 changes: 31 additions & 0 deletions cmd/tools/sql/main_cgo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package main

import (
_ "go.temporal.io/server/common/persistence/sql/sqlplugin/sqlite" // needed to load sqlite plugin
)
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/cluster_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/execution_maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
3 changes: 3 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand All @@ -32,6 +34,7 @@ import (
"errors"

"go.temporal.io/api/serviceerror"

"go.temporal.io/server/common/persistence/sql/sqlplugin"
)

Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/shard.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/typeconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import "time"
Expand Down
2 changes: 2 additions & 0 deletions common/persistence/sql/sqlplugin/sqlite/visibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package sqlite

import (
Expand Down
3 changes: 3 additions & 0 deletions common/persistence/sql/sqlplugin/tests/sqlite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

//go:build cgo

package tests

import (
"fmt"
"testing"

"github.com/stretchr/testify/suite"

"go.temporal.io/server/common/config"
"go.temporal.io/server/common/persistence/sql"
"go.temporal.io/server/common/persistence/sql/sqlplugin"
Expand Down
10 changes: 10 additions & 0 deletions develop/buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ steps:

- wait

- label: ":golang: build without cgo"
agents:
queue: "default"
docker: "*"
command: "CGO_ENABLED=0 make bins"
plugins:
- docker-compose#v3.8.0:
run: build
config: ./develop/buildkite/docker-compose.yml

- label: ":golang: unit test"
agents:
queue: "default"
Expand Down

0 comments on commit 0ff1b16

Please sign in to comment.