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

[+] Added Makefile + Checking script for Go version #222

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:22.04
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already a Dockerfile here: https://github.com/cerberauth/vulnapi/tree/main/.docker

Why would be the purpose for this new Dockerfile?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though having a "global" Dockerfile, aimed at "contained build and run" could be usefull, but you're absolutely right, there is no need for another Dockerfile.


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" ]
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
55 changes: 55 additions & 0 deletions scripts/verify_go_version.rb
Original file line number Diff line number Diff line change
@@ -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)