Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Docker Support for license DB #64

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# SPDX-FileCopyrightText: 2024 Kaushlendra Pratap <[email protected]>
# SPDX-License-Identifier: GPL-2.0-only
FROM golang:1.20 AS build

WORKDIR /LicenseDb

COPY go.mod go.sum ./
RUN go mod download

COPY cmd/ cmd/
COPY pkg/ pkg/
COPY docs/ docs/

RUN wget https://raw.githubusercontent.com/fossology/fossology/master/install/db/licenseRef.json -O licenseRef.json

RUN CGO_ENABLED=0 GOOS=linux go build -a -o laas ./cmd/laas

# Release Stage
FROM alpine:3.20 AS build-release

WORKDIR /app

COPY entrypoint.sh /app/entrypoint.sh

RUN apk add --no-cache openssl bash \
&& addgroup -S noroot \
&& adduser -S noroot -G noroot

COPY --from=build /LicenseDb/licenseRef.json /app/licenseRef.json
COPY --from=build /LicenseDb/laas /app/laas

EXPOSE 8080

RUN chmod +rx /app/entrypoint.sh \
&& touch /app/.env \
&& chown --recursive noroot:noroot /app

USER noroot:noroot

ENTRYPOINT [ "/app/entrypoint.sh" ]
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2024 Kaushlendra Pratap <[email protected]>
# SPDX-License-Identifier: GPL-2.0-only
services:
licensedb:
container_name: licensedb
build:
context: .
environment:
DB_PASSWORD: fossy
DB_HOST: postgres
DB_PORT: 5432
DB_USER: fossy
DB_NAME: fossology
POPULATE_DB: true
GIN_MODE: debug
ports:
- 8080:8080
depends_on:
postgres:
condition: service_healthy
restart: always
networks:
- licensedb-network
postgres:
container_name: postgres
image: postgres:16
environment:
POSTGRES_PASSWORD: fossy
POSTGRES_USER: fossy
POSTGRES_DB: fossology
# ports:
# - "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
restart: always
healthcheck:
test: ["CMD-SHELL", "pg_isready --dbname $$POSTGRES_DB --username $$POSTGRES_USER"]
interval: 10s
timeout: 5s
retries: 5
networks:
- licensedb-network
networks:
licensedb-network:
driver: bridge
volumes:
pgdata:
19 changes: 19 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2024 Kaushlendra Pratap <[email protected]>
# SPDX-License-Identifier: GPL-2.0-only

set -e

db_host="${DB_HOST:-localhost}"
db_port="${DB_PORT:-5432}"
db_name="${DB_NAME:-fossology}"
db_user="${DB_USER:-fossy}"
db_password="${DB_PASSWORD:-fossy}"
populate_db="${POPULATE_DB:-true}"
data_file="/app/licenseRef.json"

printf "TOKEN_HOUR_LIFESPAN=24\nAPI_SECRET=%s\n" $(openssl rand -hex 32) > /app/.env

/app/laas -host=$db_host -port=$db_port -user=$db_user -dbname=$db_name \
-password=$db_password -datafile="$data_file" -populatedb=$populate_db

Loading