Skip to content

Commit

Permalink
added docker build + docker compose (#28)
Browse files Browse the repository at this point in the history
* added docker build + docker compose

* remove redudant line

* fixed hardcoded version issue
  • Loading branch information
RabbITCybErSeC authored Aug 1, 2024
1 parent 53faabb commit 2f522ac
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:alpine as builder
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates

FROM scratch
LABEL MAINTAINER Author maarten de kruijf, RabbITCybErSeC

ARG BINARY_NAME=soarca-gui
ARG VERSION

COPY bin/${BINARY_NAME}-${VERSION}-linux-amd64 /bin/soarca-gui
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

WORKDIR /bin

EXPOSE 8081

CMD ["./soarca-gui"]
28 changes: 25 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
.PHONY: dev-server dev-tailwind dev-templ dev build-server build-tailwind build-templ build launch deploy clean


BINARY_NAME = soarca-gui
DIRECTORY = $(sort $(dir $(wildcard ./test/*/)))
VERSION = $(shell git describe --tags --dirty)
BUILDTIME := $(shell date '+%Y-%m-%dT%T%z')

GOLDFLAGS += -X main.Version=$(VERSION)
GOLDFLAGS += -X main.Buildtime=$(BUILDTIME)
GOFLAGS = -ldflags "$(GOLDFLAGS)"
#-----------------------------------------------------
# DEV
#-----------------------------------------------------


dev:
@make -j dev-templ dev-tailwind dev-server

Expand Down Expand Up @@ -37,14 +47,23 @@ dev-templ:

dev-tailwind:
@make ARGS="--watch" build-tailwind


#-----------------------------------------------------
# BUILD
#-----------------------------------------------------

build: build-templ build-tailwind build-server

build-server:
@go build -o bin/server ./server/main.go
echo "Compiling for every OS and Platform"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-linux-amd64 $(GOFLAGS) ./server/main.go
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o bin/${BINARY_NAME}-${VERSION}-darwin-arm64 $(GOFLAGS) ./server/main.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/${BINARY_NAME}-${VERSION}-windows-amd64 $(GOFLAGS) ./server/main.go


docker:
docker build --no-cache -t soarca-gui:${VERSION} --build-arg="VERSION=${VERSION}" .

build-templ:
@templ generate
Expand All @@ -56,8 +75,11 @@ lint: build-templ
GOFLAGS=-buildvcs=false golangci-lint run --timeout 5m0s -v

clean:
find . -type f -name '*_templ.go' -exec rm -f {} \;
rm -rf build/soarca* build/main
rm -rf bin/*
find . -type f -name "*_templ.go" -delete


run: docker
GIT_VERSION=${VERSION} docker compose up --build --force-recreate -d

.DEFAULT_GOAL := dev
57 changes: 57 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
version: '3.7'
services:
mongodb_container:
image: mongo:latest
container_name: mongo_soarca_stack
environment:
MONGO_INITDB_ROOT_USERNAME: "root"
MONGO_INITDB_ROOT_PASSWORD: "rootpassword"
networks:
- db-net
volumes:
- mongodb_data_container:/data/db

soarca:
image: cossas/soarca:1.0.0-42-g8b62b16
container_name: soarca_server
environment:
PORT: 8080
SOARCA_ALLOWED_ORIGINS: "*"
GIN_MODE: "release"
MONGODB_URI: "mongodb://mongodb_container:27017"
DATABASE_NAME: "soarca"
DB_USERNAME: "root"
DB_PASSWORD: "rootpassword"
PLAYBOOK_API_LOG_LEVEL: trace
DATABASE: "false"
HTTP_SKIP_CERT_VALIDATION: false
networks:
- db-net
- soarca-net
ports:
- 127.0.0.1:8080:8080
depends_on:
- mongodb_container

soarca-gui:
build:
dockerfile: Dockerfile
args:
VERSION: "${GIT_VERSION}"
container_name: soarca_gui
environment:
SOARCA_URI: "http://soarca_server:8080"
networks:
- soarca-net
ports:
- 127.0.0.1:8081:8081
depends_on:
- soarca

networks:
db-net:
soarca-net:


volumes:
mongodb_data_container:

0 comments on commit 2f522ac

Please sign in to comment.