mirror of https://github.com/harness/drone.git
parent
edadd5e91b
commit
1c762c6802
|
@ -9,7 +9,7 @@
|
|||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "auto",
|
||||
"buildFlags": "-tags=sqlite",
|
||||
"buildFlags": "-tags=gogit",
|
||||
"program": "cmd/gitness",
|
||||
"args": ["server", "../../.local.env"]
|
||||
}
|
||||
|
|
26
Dockerfile
26
Dockerfile
|
@ -1,7 +1,7 @@
|
|||
# ---------------------------------------------------------#
|
||||
# Build web image #
|
||||
# ---------------------------------------------------------#
|
||||
FROM node:16 as web
|
||||
FROM --platform=$BUILDPLATFORM node:16 as web
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
|
@ -18,14 +18,13 @@ RUN yarn && yarn build && yarn cache clean
|
|||
# ---------------------------------------------------------#
|
||||
# Build gitness image #
|
||||
# ---------------------------------------------------------#
|
||||
FROM golang:1.19-alpine as builder
|
||||
FROM --platform=$BUILDPLATFORM golang:1.19-alpine as builder
|
||||
|
||||
RUN apk update \
|
||||
&& apk add --no-cache protoc build-base git
|
||||
|
||||
# Setup workig dir
|
||||
WORKDIR /app
|
||||
|
||||
RUN git config --global --add safe.directory '/app'
|
||||
|
||||
# Get dependancies - will also be cached if we won't change mod/sum
|
||||
|
@ -45,22 +44,31 @@ ARG GIT_COMMIT
|
|||
ARG GITNESS_VERSION_MAJOR
|
||||
ARG GITNESS_VERSION_MINOR
|
||||
ARG GITNESS_VERSION_PATCH
|
||||
ARG BUILD_TAGS
|
||||
ARG TARGETOS TARGETARCH
|
||||
|
||||
RUN if [ "$TARGETARCH" = "arm64" ]; then \
|
||||
wget -P ~ https://musl.cc/aarch64-linux-musl-cross.tgz && \
|
||||
tar -xvf ~/aarch64-linux-musl-cross.tgz -C ~ ; \
|
||||
fi
|
||||
|
||||
# set required build flags
|
||||
RUN CGO_ENABLED=1 \
|
||||
BUILD_TAGS=${BUILD_TAGS} \
|
||||
make build
|
||||
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||
--mount=type=cache,target=/go/pkg \
|
||||
if [ "$TARGETARCH" = "arm64" ]; then CC=~/aarch64-linux-musl-cross/bin/aarch64-linux-musl-gcc; fi && \
|
||||
LDFLAGS="-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.major=${GITNESS_VERSION_MAJOR} -X github.com/harness/gitness/version.minor=${GITNESS_VERSION_MINOR} -X github.com/harness/gitness/version.patch=${GITNESS_VERSION_PATCH} -extldflags '-static'" && \
|
||||
CGO_ENABLED=1 \
|
||||
GOOS=$TARGETOS GOARCH=$TARGETARCH \
|
||||
CC=$CC go build -tags=gogit -ldflags="$LDFLAGS" -o ./gitness ./cmd/gitness
|
||||
|
||||
### Pull CA Certs
|
||||
FROM alpine:latest as cert-image
|
||||
FROM --platform=$BUILDPLATFORM alpine:latest as cert-image
|
||||
|
||||
RUN apk --update add ca-certificates
|
||||
|
||||
# ---------------------------------------------------------#
|
||||
# Create final image #
|
||||
# ---------------------------------------------------------#
|
||||
FROM alpine/git:2.40.1 as final
|
||||
FROM --platform=$BUILDPLATFORM alpine/git:2.40.1 as final
|
||||
|
||||
# setup app dir and its content
|
||||
WORKDIR /app
|
||||
|
|
13
Makefile
13
Makefile
|
@ -8,8 +8,6 @@ endif
|
|||
tools = $(addprefix $(GOBIN)/, golangci-lint goimports govulncheck protoc-gen-go protoc-gen-go-grpc gci)
|
||||
deps = $(addprefix $(GOBIN)/, wire dbmate)
|
||||
|
||||
LDFLAGS = "-X github.com/harness/gitness/version.GitCommit=${GIT_COMMIT} -X github.com/harness/gitness/version.major=${GITNESS_VERSION_MAJOR} -X github.com/harness/gitness/version.minor=${GITNESS_VERSION_MINOR} -X github.com/harness/gitness/version.patch=${GITNESS_VERSION_PATCH}"
|
||||
|
||||
ifneq (,$(wildcard ./.local.env))
|
||||
include ./.local.env
|
||||
export
|
||||
|
@ -17,12 +15,6 @@ endif
|
|||
|
||||
.DEFAULT_GOAL := all
|
||||
|
||||
ifeq ($(BUILD_TAGS),)
|
||||
BUILD_TAGS := sqlite
|
||||
endif
|
||||
|
||||
BUILD_TAGS := $(BUILD_TAGS),gogit
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Initialization
|
||||
|
@ -48,16 +40,13 @@ tools: $(tools) ## Install tools required for the build
|
|||
|
||||
build: generate ## Build the all-in-one gitness binary
|
||||
@echo "Building Gitness Server"
|
||||
go build -tags=${BUILD_TAGS} -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
||||
go build -tags=gogit -o ./gitness ./cmd/gitness
|
||||
|
||||
test: generate ## Run the go tests
|
||||
@echo "Running tests"
|
||||
go test -v -coverprofile=coverage.out ./...
|
||||
go tool cover -html=coverage.out
|
||||
|
||||
run: dep ## Run the gitness binary from source
|
||||
@go run -race -ldflags=${LDFLAGS} ./cmd/gitness
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# Code Formatting and linting
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build pq
|
||||
// +build pq
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build sqlite
|
||||
// +build sqlite
|
||||
//go:build !nosqlite
|
||||
// +build !nosqlite
|
||||
|
||||
package main
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build pq
|
||||
// +build pq
|
||||
//go:build nosqlite
|
||||
// +build nosqlite
|
||||
|
||||
package database
|
||||
|
|
@ -12,12 +12,13 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !pq
|
||||
// +build !pq
|
||||
//go:build !nosqlite
|
||||
// +build !nosqlite
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
@ -29,5 +30,10 @@ func isSQLUniqueConstraintError(original error) bool {
|
|||
errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintPrimaryKey)
|
||||
}
|
||||
|
||||
var pqErr *pq.Error
|
||||
if errors.As(original, &pqErr) {
|
||||
return pqErr.Code == "23505" // unique_violation
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -12,9 +12,6 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !proxy
|
||||
// +build !proxy
|
||||
|
||||
// Package dist embeds the static web server content.
|
||||
package web
|
||||
|
||||
|
|
Loading…
Reference in New Issue