diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7811206 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM ubuntu:22.04 + +WORKDIR /app/ + +RUN apt-get update +RUN apt-get upgrade -y + +RUN apt-get install -y ruby +RUN apt-get install -y curl +RUN apt-get install -y make + +RUN rm -rf /usr/local/go + +RUN curl -L -o /tmp/go.tar.gz https://go.dev/dl/go1.23.3.linux-amd64.tar.gz +RUN tar -C /usr/local -xzf /tmp/go.tar.gz + +ENV PATH=/usr/local/go/bin:$PATH + +COPY ./ /app/ + +RUN make + +ENTRYPOINT [ "/app/vulnapi" ] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..93f1904 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ +BIN = vulnapi +.DEFAULT_GOAL := $(BIN) +MIN_GO_VERSION = go1.23.0 + +.PHONY: check_versions clean +check_versions: +ifeq (, $(shell which go)) + $(error "No go command in $(PATH), consider doing apt-get install golang-go") +endif +ifeq (, $(shell which ruby)) + $(error "No ruby command in $(PATH), consider doing apt-get install ruby") +endif +ifneq (0, $(shell ruby ./scripts/verify_go_version.rb $(MIN_GO_VERSION) 2>&1 >/dev/null; echo $$?)) + $(error "Your go version is too old/invalid !") +endif + +$(BIN): check_versions + go build -o $(BIN) + +clean: check_versions + go clean diff --git a/scripts/verify_go_version.rb b/scripts/verify_go_version.rb new file mode 100644 index 0000000..28dada7 --- /dev/null +++ b/scripts/verify_go_version.rb @@ -0,0 +1,55 @@ +require 'open3' + +def error(message, code = 1) + # STDERR.puts(message) + exit(code) +end + +def usage + "Usage: #{File.basename($PROGRAM_NAME)} [target min go version]" +end + +def get_system_go_version + go_path, status = Open3.capture2('which go') + error('go: command not found') unless status.success? + + output, status = Open3.capture2('go version') + error('Failed to retrieve Go version') unless status.success? + + pattern = /\bgo(\d+)\.(\d+)\.(\d+)\b/ + match = output.match(pattern) + if match + major, minor, patch = match.captures.map(&:to_i) + return [major, minor, patch] + end + + error("System Go version doesn't match the Go versioning system (goXX.YY.ZZ)!") +end + +def parse_go_semver(entry) + pattern = /^go(\d+)\.(\d+)\.(\d+)$/ + match = entry.match(pattern) + if match + major, minor, patch = match.captures.map(&:to_i) + return [major, minor, patch] + end + + error("\"#{entry}\" doesn't match the Go versioning system (goXX.YY.ZZ)!") +end + +def main + error(usage, 1) unless ARGV.size == 1 + + min_version = parse_go_semver(ARGV[0]) + cur_version = get_system_go_version + + 3.times do |i| + if cur_version[i] < min_version[i] + error("Installed Go version go#{cur_version.join('.')} is older than the minimum required version go#{min_version.join('.')}") + end + end + + 0 +end + +exit(main)