mirror of
https://github.com/harness/drone.git
synced 2025-05-04 14:30:28 +08:00
move docker files for harness in harness folder
This commit is contained in:
parent
9f7bae0330
commit
f7bdcc9323
@ -1,7 +1,8 @@
|
|||||||
### Build web
|
# ---------------------------------------------------------#
|
||||||
|
# Build web image #
|
||||||
|
# ---------------------------------------------------------#
|
||||||
FROM node:16 as web
|
FROM node:16 as web
|
||||||
|
|
||||||
# Create app directory
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
COPY web/package.json ./
|
COPY web/package.json ./
|
||||||
@ -17,7 +18,9 @@ COPY .npmrc /root/.npmrc
|
|||||||
|
|
||||||
RUN yarn && yarn build && yarn cache clean
|
RUN yarn && yarn build && yarn cache clean
|
||||||
|
|
||||||
### Build gitness
|
# ---------------------------------------------------------#
|
||||||
|
# Build gitness image #
|
||||||
|
# ---------------------------------------------------------#
|
||||||
FROM golang:1.19-alpine as builder
|
FROM golang:1.19-alpine as builder
|
||||||
|
|
||||||
RUN apk update \
|
RUN apk update \
|
||||||
@ -48,41 +51,38 @@ ARG GIT_COMMIT
|
|||||||
ARG GITNESS_VERSION_MAJOR
|
ARG GITNESS_VERSION_MAJOR
|
||||||
ARG GITNESS_VERSION_MINOR
|
ARG GITNESS_VERSION_MINOR
|
||||||
ARG GITNESS_VERSION_PATCH
|
ARG GITNESS_VERSION_PATCH
|
||||||
|
ARG BUILD_TAGS
|
||||||
|
|
||||||
# set required build flags
|
# set required build flags
|
||||||
ARG sqlite
|
RUN CGO_ENABLED=1 \
|
||||||
RUN if [[ -z "$sqlite" ]] ; then \
|
|
||||||
CGO_ENABLED=0 \
|
|
||||||
GOOS=linux \
|
GOOS=linux \
|
||||||
GOARCH=amd64 \
|
GOARCH=amd64 \
|
||||||
make harness-build-pq \
|
BUILD_TAGS=${BUILD_TAGS} \
|
||||||
; else \
|
make build
|
||||||
CGO_ENABLED=1 \
|
|
||||||
GOOS=linux \
|
|
||||||
GOARCH=amd64 \
|
|
||||||
make harness-build \
|
|
||||||
; fi
|
|
||||||
|
|
||||||
### Pull CA Certs
|
### Pull CA Certs
|
||||||
FROM alpine:latest as cert-image
|
FROM alpine:latest as cert-image
|
||||||
|
|
||||||
RUN apk --update add ca-certificates
|
RUN apk --update add ca-certificates
|
||||||
|
|
||||||
### Create final image
|
# ---------------------------------------------------------#
|
||||||
FROM us.gcr.io/platform-205701/ubi/ubi-go:8.7 as final
|
# Create final image #
|
||||||
|
# ---------------------------------------------------------#
|
||||||
|
FROM alpine/git:2.36.3 as final
|
||||||
|
|
||||||
USER root
|
RUN adduser -u 1001 -D -h /app iamuser
|
||||||
RUN mkdir /app && chown nobody:nobody /app
|
|
||||||
|
|
||||||
USER nobody
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY --chown=nobody:nobody --from=cert-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
COPY --from=cert-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||||
COPY --chown=nobody:nobody --from=builder /app/gitness /app/gitness
|
COPY --from=builder /app/gitness /app/gitness
|
||||||
|
|
||||||
|
RUN chown -R 1001:1001 /app
|
||||||
RUN chmod -R 700 /app/gitness
|
RUN chmod -R 700 /app/gitness
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
EXPOSE 3001
|
EXPOSE 3001
|
||||||
|
|
||||||
|
USER 1001
|
||||||
|
|
||||||
ENTRYPOINT [ "/app/gitness", "server" ]
|
ENTRYPOINT [ "/app/gitness", "server" ]
|
26
Makefile
26
Makefile
@ -49,27 +49,15 @@ generate: $(mocks) wire mocks/mock_client.go proto
|
|||||||
|
|
||||||
build: generate ## Build the all-in-one gitness binary
|
build: generate ## Build the all-in-one gitness binary
|
||||||
@echo "Building Gitness Server"
|
@echo "Building Gitness Server"
|
||||||
go build -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
go build -tags=${BUILD_TAGS} -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
||||||
|
|
||||||
build-pq: generate ## Build the all-in-one gitness binary
|
|
||||||
@echo "Building Gitness Server"
|
|
||||||
go build -tags=pq -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
|
||||||
|
|
||||||
harness-build: generate ## Build the all-in-one gitness binary for harness embedded mode
|
|
||||||
@echo "Building Gitness Server for Harness"
|
|
||||||
go build -tags=harness -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
|
||||||
|
|
||||||
harness-build-pq: generate ## Build the all-in-one gitness binary for harness embedded mode using postgres
|
|
||||||
@echo "Building Gitness Server for Harness"
|
|
||||||
go build -tags=harness,pq -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
|
|
||||||
|
|
||||||
build-gitrpc: generate ## Build the gitrpc binary
|
build-gitrpc: generate ## Build the gitrpc binary
|
||||||
@echo "Building GitRPC Server"
|
@echo "Building GitRPC Server"
|
||||||
go build -ldflags=${LDFLAGS} -o ./gitrpcserver ./cmd/gitrpcserver
|
go build -tags=${BUILD_TAGS} -ldflags=${LDFLAGS} -o ./gitrpcserver ./cmd/gitrpcserver
|
||||||
|
|
||||||
build-githook: generate ## Build the githook binary
|
build-githook: generate ## Build the githook binary
|
||||||
@echo "Building GitHook Binary"
|
@echo "Building GitHook Binary"
|
||||||
go build -ldflags=${LDFLAGS} -o ./githook ./cmd/githook
|
go build -tags=${BUILD_TAGS} -ldflags=${LDFLAGS} -o ./githook ./cmd/githook
|
||||||
|
|
||||||
test: generate ## Run the go tests
|
test: generate ## Run the go tests
|
||||||
@echo "Running tests"
|
@echo "Running tests"
|
||||||
@ -107,20 +95,20 @@ test-env: stop ## Run test environment - this runs all services and the gitness
|
|||||||
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.test.yml up -d ${DOCKER_BUILD_OPTS} --remove-orphans
|
docker-compose -f ./docker/docker-compose.yml -f ./docker/docker-compose.test.yml up -d ${DOCKER_BUILD_OPTS} --remove-orphans
|
||||||
|
|
||||||
image: ## Build the gitness docker image
|
image: ## Build the gitness docker image
|
||||||
@echo "Building Gitness Image"
|
@echo "Building Gitness Standalone Image"
|
||||||
@docker build \
|
@docker build \
|
||||||
--secret id=npmrc,src=${HOME}/.npmrc \
|
|
||||||
--build-arg GITNESS_VERSION=latest \
|
--build-arg GITNESS_VERSION=latest \
|
||||||
|
--build-arg BUILD_TAGS=${BUILD_TAGS} \
|
||||||
--build-arg GIT_COMMIT=${GIT_COMMIT} \
|
--build-arg GIT_COMMIT=${GIT_COMMIT} \
|
||||||
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
|
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
-t gitness:latest \
|
-t gitness-standalone:latest .
|
||||||
-f ./docker/Dockerfile .
|
|
||||||
|
|
||||||
gitrpc-image: ## Build the gitness gitrpc docker image
|
gitrpc-image: ## Build the gitness gitrpc docker image
|
||||||
@echo "Building Gitness GitRPC Image"
|
@echo "Building Gitness GitRPC Image"
|
||||||
@docker build \
|
@docker build \
|
||||||
--build-arg GITNESS_VERSION=latest \
|
--build-arg GITNESS_VERSION=latest \
|
||||||
|
--build-arg BUILD_TAGS=${BUILD_TAGS} \
|
||||||
--build-arg GIT_COMMIT=${GIT_COMMIT} \
|
--build-arg GIT_COMMIT=${GIT_COMMIT} \
|
||||||
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
|
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
|
@ -7,7 +7,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/harness/gitness/events"
|
"github.com/harness/gitness/events"
|
||||||
"github.com/harness/gitness/gitrpc"
|
"github.com/harness/gitness/gitrpc"
|
||||||
server2 "github.com/harness/gitness/gitrpc/server"
|
server2 "github.com/harness/gitness/gitrpc/server"
|
||||||
|
@ -7,7 +7,6 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/harness/gitness/events"
|
"github.com/harness/gitness/events"
|
||||||
"github.com/harness/gitness/gitrpc"
|
"github.com/harness/gitness/gitrpc"
|
||||||
server2 "github.com/harness/gitness/gitrpc/server"
|
server2 "github.com/harness/gitness/gitrpc/server"
|
||||||
|
@ -1,65 +0,0 @@
|
|||||||
### Build operator
|
|
||||||
FROM golang:1.19-alpine as builder
|
|
||||||
|
|
||||||
RUN apk update \
|
|
||||||
&& apk add --no-cache protoc build-base git
|
|
||||||
|
|
||||||
# Setup workig dir
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
# Access to private repos
|
|
||||||
ARG GITHUB_ACCESS_TOKEN
|
|
||||||
RUN git config --global url."https://${GITHUB_ACCESS_TOKEN}:x-oauth-basic@github.com/harness".insteadOf "https://github.com/harness"
|
|
||||||
RUN git config --global --add safe.directory '/app'
|
|
||||||
RUN go env -w GOPRIVATE=github.com/harness/*
|
|
||||||
|
|
||||||
# Get dependancies - will also be cached if we won't change mod/sum
|
|
||||||
COPY go.mod .
|
|
||||||
COPY go.sum .
|
|
||||||
COPY Makefile .
|
|
||||||
RUN make dep
|
|
||||||
RUN make tools
|
|
||||||
# COPY the source code as the last step
|
|
||||||
COPY . .
|
|
||||||
# set required build flags
|
|
||||||
ENV CGO_ENABLED=0 \
|
|
||||||
GOOS=linux \
|
|
||||||
GOARCH=amd64
|
|
||||||
|
|
||||||
# build
|
|
||||||
ARG GIT_COMMIT
|
|
||||||
ARG GITNESS_VERSION_MAJOR
|
|
||||||
ARG GITNESS_VERSION_MINOR
|
|
||||||
ARG GITNESS_VERSION_PATCH
|
|
||||||
RUN make build-gitrpc
|
|
||||||
RUN make build-githook
|
|
||||||
|
|
||||||
### Pull CA Certs
|
|
||||||
FROM alpine:latest as cert-image
|
|
||||||
|
|
||||||
RUN apk --update add ca-certificates
|
|
||||||
|
|
||||||
### Create final image
|
|
||||||
FROM us.gcr.io/platform-205701/ubi/ubi-go:8.7 as final
|
|
||||||
|
|
||||||
USER root
|
|
||||||
RUN microdnf update && \
|
|
||||||
microdnf install git
|
|
||||||
RUN mkdir /app && chown nobody:nobody /app
|
|
||||||
|
|
||||||
USER nobody
|
|
||||||
WORKDIR /app
|
|
||||||
|
|
||||||
COPY --chown=nobody:nobody --from=cert-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
|
||||||
COPY --chown=nobody:nobody --from=builder /app/gitrpcserver /app/gitrpcserver
|
|
||||||
COPY --chown=nobody:nobody --from=builder /app/githook /app/githook
|
|
||||||
|
|
||||||
RUN chmod -R 700 /app/gitrpcserver
|
|
||||||
RUN chmod -R 700 /app/githook
|
|
||||||
|
|
||||||
EXPOSE 3001
|
|
||||||
|
|
||||||
# configure gitrpc to use githook (as they come bundled in the image)
|
|
||||||
ENV GITRPC_SERVER_GIT_HOOK_PATH="/app/githook"
|
|
||||||
|
|
||||||
ENTRYPOINT [ "/app/gitrpcserver" ]
|
|
@ -1,39 +0,0 @@
|
|||||||
version: "3.9"
|
|
||||||
|
|
||||||
services:
|
|
||||||
db:
|
|
||||||
image: postgres
|
|
||||||
restart: always
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: gitness
|
|
||||||
POSTGRES_USER: gitness
|
|
||||||
POSTGRES_PASSWORD: gitness
|
|
||||||
PGDATA: /var/lib/postgresql/data/pgdata
|
|
||||||
ports:
|
|
||||||
- "5432:5432"
|
|
||||||
expose:
|
|
||||||
- 5432
|
|
||||||
volumes:
|
|
||||||
- ./init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh
|
|
||||||
- gitness_data:/var/lib/postgresql/data
|
|
||||||
|
|
||||||
migration:
|
|
||||||
build:
|
|
||||||
context: ../db
|
|
||||||
dockerfile: ./Dockerfile
|
|
||||||
environment:
|
|
||||||
DATABASE_URL: postgres://gitness:gitness@db:5432/gitness?sslmode=disable
|
|
||||||
depends_on:
|
|
||||||
- db
|
|
||||||
|
|
||||||
redis:
|
|
||||||
image: redis:6.0
|
|
||||||
container_name: cache
|
|
||||||
ports:
|
|
||||||
- "6379:6379"
|
|
||||||
expose:
|
|
||||||
- 6379
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
gitness_data:
|
|
||||||
driver: local
|
|
@ -1,7 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
set -e
|
|
||||||
|
|
||||||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
|
|
||||||
CREATE DATABASE gitness_test;
|
|
||||||
GRANT ALL PRIVILEGES ON DATABASE gitness_test TO "$POSTGRES_USER";
|
|
||||||
EOSQL
|
|
Loading…
Reference in New Issue
Block a user