move docker files for harness in harness folder

jobatzil/rename
Enver Bisevac 2023-06-09 16:51:57 +02:00
parent 9f7bae0330
commit f7bdcc9323
7 changed files with 27 additions and 152 deletions

View File

@ -1,7 +1,8 @@
### Build web
# ---------------------------------------------------------#
# Build web image #
# ---------------------------------------------------------#
FROM node:16 as web
# Create app directory
WORKDIR /usr/src/app
COPY web/package.json ./
@ -17,7 +18,9 @@ COPY .npmrc /root/.npmrc
RUN yarn && yarn build && yarn cache clean
### Build gitness
# ---------------------------------------------------------#
# Build gitness image #
# ---------------------------------------------------------#
FROM golang:1.19-alpine as builder
RUN apk update \
@ -48,41 +51,38 @@ ARG GIT_COMMIT
ARG GITNESS_VERSION_MAJOR
ARG GITNESS_VERSION_MINOR
ARG GITNESS_VERSION_PATCH
ARG BUILD_TAGS
# set required build flags
ARG sqlite
RUN if [[ -z "$sqlite" ]] ; then \
CGO_ENABLED=0 \
RUN CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
make harness-build-pq \
; else \
CGO_ENABLED=1 \
GOOS=linux \
GOARCH=amd64 \
make harness-build \
; fi
BUILD_TAGS=${BUILD_TAGS} \
make build
### 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
# ---------------------------------------------------------#
# Create final image #
# ---------------------------------------------------------#
FROM alpine/git:2.36.3 as final
USER root
RUN mkdir /app && chown nobody:nobody /app
RUN adduser -u 1001 -D -h /app iamuser
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/gitness /app/gitness
COPY --from=cert-image /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder /app/gitness /app/gitness
RUN chown -R 1001:1001 /app
RUN chmod -R 700 /app/gitness
EXPOSE 3000
EXPOSE 3001
USER 1001
ENTRYPOINT [ "/app/gitness", "server" ]

View File

@ -49,27 +49,15 @@ generate: $(mocks) wire mocks/mock_client.go proto
build: generate ## Build the all-in-one gitness binary
@echo "Building Gitness Server"
go build -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
go build -tags=${BUILD_TAGS} -ldflags=${LDFLAGS} -o ./gitness ./cmd/gitness
build-gitrpc: generate ## Build the gitrpc binary
@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
@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
@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
image: ## Build the gitness docker image
@echo "Building Gitness Image"
@echo "Building Gitness Standalone Image"
@docker build \
--secret id=npmrc,src=${HOME}/.npmrc \
--build-arg GITNESS_VERSION=latest \
--build-arg BUILD_TAGS=${BUILD_TAGS} \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
--platform linux/amd64 \
-t gitness:latest \
-f ./docker/Dockerfile .
-t gitness-standalone:latest .
gitrpc-image: ## Build the gitness gitrpc docker image
@echo "Building Gitness GitRPC Image"
@docker build \
--build-arg GITNESS_VERSION=latest \
--build-arg BUILD_TAGS=${BUILD_TAGS} \
--build-arg GIT_COMMIT=${GIT_COMMIT} \
--build-arg GITHUB_ACCESS_TOKEN=${GITHUB_ACCESS_TOKEN} \
--platform linux/amd64 \

View File

@ -7,7 +7,6 @@ package server
import (
"context"
"github.com/harness/gitness/events"
"github.com/harness/gitness/gitrpc"
server2 "github.com/harness/gitness/gitrpc/server"

View File

@ -7,7 +7,6 @@ package server
import (
"context"
"github.com/harness/gitness/events"
"github.com/harness/gitness/gitrpc"
server2 "github.com/harness/gitness/gitrpc/server"

View File

@ -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" ]

View File

@ -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

View File

@ -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