Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit d13ffdd

Browse files
fiorixskogtwin
authored andcommitted
Update build and release systems
This diff removes the build_tarballs.sh and the rpm/Makefile files and moves their logic into the main Makefile. The build system places binary files in the build directory. The release system copy those files over to the release directory, preparing it for travis to pick up. Examples: make binary_deb binary_rpm VERSION=1.0 make clean binary_tar VERSION=1.0 GOOS=linux GOARCH=amd64 make distclean release VERSION=1.0 Deleted the debian/copyright file because it was outdated; I think this could be automated with debmake but didn't spend time on it. There's other minor changes like removing trailing space from files, updating and adding documentation. Re-add copyright notice to vulndb/schema.go.
1 parent 22a9e3c commit d13ffdd

File tree

10 files changed

+188
-407
lines changed

10 files changed

+188
-407
lines changed

.travis.yml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ services:
1010
mysql
1111

1212
before_install:
13-
- sudo apt-get install -y rpm build-essential debhelper dh-make fakeroot
13+
- sudo apt-get install -y rpm build-essential debhelper dh-make fakeroot zip
1414
- mysql -e 'CREATE DATABASE vulndb;'
1515

1616
env:
1717
- MYSQL_TEST_DSN=root@/vulndb
1818

1919
script:
20-
- go get -v -u ./...
20+
- go get -v -u -d ./...
2121
- go test -v ./...
2222

2323
before_deploy:
24-
- export VERSION=${TRAVIS_TAG:1}
25-
- chmod +x build_tarballs.sh && ./build_tarballs.sh
26-
- make -C rpm/
27-
- dpkg-buildpackage -rfakeroot -uc -us && mv ../*.deb release
24+
- make release VERSION=${TRAVIS_TAG:1}
2825

2926
deploy:
3027
provider: releases
3128
api_key:
3229
secure: hnofbIf34EiluDy1u288ZVu1CM7f8MxKY8T40Tkj6dj6CBJAtEscm6AQiXP2v2TVLK0mOAtpZ8gK6oGRE6jVmKxrLZNKhuL1E3XNfi5poED8kW0hjjXBCWMG5tLrXCXk7d5qYMMVTD8/eB5XBJMrfiC8GcjuD0QgzqhkQiJdpBnMZj5NamL0JR6Tht2turSglwWAQ9E0GdIaHYpHwN4IJ2wkh0kBoR7uJrIU9F5STOO0OqgJ8LZ9YwCtljgz9XvJt3W6Xds+AH0w/MtfhZucJXG20vCYaTMxdFKoQxitol/YISIOD/P4MhFBzmf2O2Cw5X517owAb++wkfYL+E2NEhVilZlKkTTHBNzCRzO85GGsDCBv91MSDTykZwu047/VWvxxIpGPTC7bQnYFcgWTc3d93pBERRL1ppfzNlU/CPIebLj5KPCCkSzb1RTEy8gOL2aoKzqImv/428P+FVaaibbM0M87OM3iWOe1yGRXUVQtc2CMNdNukr7/p4HFaptPyBu9OjnNsqjsI+yS1flqrDpFbkBV5ZDUhy0tPyu59m9l34qrrGJ1nJdiZvcNgAaC8VEeZ42OUuvNtl/77Wx1X7cYU8Iqz/zz/QWLqkwljQCjoXPEqIBvVyqzn+eeeRNzGDpzbxFf3MMhx7zE7QVk8M+M//SIGFMeyTHswriMkZk=
3330
file_glob: true
34-
file: release/**/*
31+
file: release/*
3532
skip_cleanup: true
3633
on:
3734
tags: true

Makefile

Lines changed: 153 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,154 @@
1-
# Go parameters
2-
GOCMD=go
3-
GOBUILD=$(GOCMD) build
4-
GOCLEAN=$(GOCMD) clean
5-
GOGET=$(GOCMD) get
6-
CPE2CVE=cpe2cve
7-
CSV2CPE=csv2cpe
8-
NVDSYNC=nvdsync
9-
RPM2CPE=rpm2cpe
10-
11-
NAME=nvdtools
12-
PKG=$(NAME)-$(VERSION)
13-
TGZ=$(PKG).tar.gz
14-
15-
all: build
16-
build:
17-
$(GOBUILD) -o $(CPE2CVE) ./cmd/$(CPE2CVE)/cpe2cve.go
18-
$(GOBUILD) -o $(CSV2CPE) ./cmd/$(CSV2CPE)/csv2cpe.go
19-
$(GOBUILD) -o $(NVDSYNC) ./cmd/$(NVDSYNC)/main.go
20-
$(GOBUILD) -o $(RPM2CPE) ./cmd/$(RPM2CPE)/rpm2cpe.go
21-
22-
clean:
23-
$(GOCLEAN)
24-
rm -f $(CPE2CVE)
25-
rm -f $(CSV2CPE)
26-
rm -f $(NVDSYNC)
27-
rm -f $(RPM2CPE)
28-
1+
# Copyright (c) Facebook, Inc. and its affiliates.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
NAME = nvdtools
16+
VERSION = tip
17+
18+
TOOLS = \
19+
cpe2cve \
20+
csv2cpe \
21+
fireeye2nvd \
22+
flexera2nvd \
23+
nvdsync \
24+
rpm2cpe \
25+
rustsec2nvd \
26+
vulndb
27+
28+
DOCS = \
29+
CODE_OF_CONDUCT.md \
30+
CONTRIBUTING.md \
31+
HOWTO.md \
32+
LICENSE \
33+
README.md
34+
35+
GO = go
36+
GOOS = $(shell $(GO) env GOOS)
37+
GOARCH = $(shell $(GO) env GOARCH)
38+
39+
TAR = tar
40+
ZIP = zip
41+
INSTALL = install
42+
43+
# Compile all tools.
44+
all: $(TOOLS)
45+
46+
# Compile TOOLS to ./build/bin/$tool using GOOS and GOARCH.
47+
$(TOOLS):
48+
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) build $(GOFLAGS) -o ./build/bin/$@ ./cmd/$@
49+
50+
# Check/fetch all dependencies.
51+
deps:
52+
GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO) get -v -d ./...
53+
54+
# install installs tools and documentation.
55+
# The install target is used by rpm and deb builders.
2956
install:
30-
install -d $(DESTDIR)/usr/bin
31-
install -p -m 0755 ./cpe2cve $(DESTDIR)/usr/bin/cpe2cve
32-
install -p -m 0755 ./csv2cpe $(DESTDIR)/usr/bin/csv2cpe
33-
install -p -m 0755 ./nvdsync $(DESTDIR)/usr/bin/nvdsync
34-
install -p -m 0755 ./rpm2cpe $(DESTDIR)/usr/bin/rpm2cpe
35-
36-
archive:
37-
touch $(TGZ)
38-
tar czf $(TGZ) --exclude=$(TGZ) --transform s/$(NAME)/$(PKG)/ ../$(NAME)
57+
# tools
58+
$(INSTALL) -d $(DESTDIR)/usr/bin
59+
for tool in $(TOOLS); do $(INSTALL) -p -m 0755 ./build/bin/$$tool $(DESTDIR)/usr/bin/$$tool; done
60+
# docs
61+
$(INSTALL) -d $(DESTDIR)/usr/share/doc/nvdtools
62+
for doc in $(DOCS); do $(INSTALL) -p -m 0644 $$doc $(DESTDIR)/usr/share/doc/nvdtools/$$doc; done
63+
64+
DIST_NAME = $(NAME)-$(VERSION)
65+
DIST_DIR = build/$(DIST_NAME)
66+
67+
# binary_dist creates a local binary distribution in DIST_DIR.
68+
binary_dist: $(TOOLS)
69+
mkdir -p $(DIST_DIR)/doc
70+
cp $(DOCS) $(DIST_DIR)/doc
71+
mv build/bin $(DIST_DIR)/bin
72+
73+
# binary_tar creates tarball of binary distribution.
74+
binary_tar: binary_dist
75+
mkdir -p build/tgz
76+
cd build && $(TAR) czf tgz/$(DIST_NAME)-$(GOOS)-$(GOARCH).tar.gz $(DIST_NAME)
77+
rm -rf $(DIST_DIR)
78+
79+
# binary_zip creates zip of binary distribution.
80+
binary_zip: binary_dist
81+
mkdir -p build/zip
82+
cd build && $(ZIP) -r zip/$(DIST_NAME)-$(GOOS)-$(GOARCH).zip $(DIST_NAME)
83+
rm -rf $(DIST_DIR)
84+
85+
# binary_deb creates debian package.
86+
#
87+
# Requires GOPATH and dependencies available to compile nvdtools.
88+
# Must set version to build: make binary_deb VERSION=1.0
89+
binary_deb:
90+
VERSION=$(VERSION) dpkg-buildpackage -rfakeroot -uc -us
91+
mkdir -p build/deb
92+
mv ../$(NAME)*.deb build/deb/
93+
94+
# archive_tar creates tarball of the source code.
95+
archive_tar:
96+
mkdir -p build/tgz
97+
$(TAR) czf build/tgz/$(DIST_NAME).tar.gz \
98+
--exclude=build \
99+
--exclude=release \
100+
--exclude=.git \
101+
--exclude=.travis.yml \
102+
--transform s/./$(DIST_NAME)/ \
103+
.
104+
105+
# binary_rpm creates rpm package.
106+
#
107+
# Requires GOPATH and dependencies available to compile nvdtools.
108+
# Must set version to build: make binary_rpm VERSION=1.0
109+
binary_rpm: archive_tar
110+
mkdir -p build/rpm/SOURCES
111+
mv build/tgz/$(DIST_NAME).tar.gz build/rpm/SOURCES/
112+
rpmbuild -ba \
113+
--define="_topdir $(PWD)/build/rpm" \
114+
--define="_version $(VERSION)" \
115+
rpm/nvdtools.spec
116+
117+
# release_tar creates tarball releases.
118+
release_tar:
119+
mkdir -p release
120+
make deps binary_tar GOOS=darwin GOARCH=amd64
121+
make deps binary_tar GOOS=freebsd GOARCH=amd64
122+
make deps binary_tar GOOS=linux GOARCH=amd64
123+
make deps binary_tar GOOS=linux GOARCH=arm64
124+
mv build/tgz/*.tar.gz release
125+
126+
# release_zip creates zip releases.
127+
release_zip:
128+
mkdir -p release
129+
make deps binary_zip GOOS=windows GOARCH=386
130+
make deps binary_zip GOOS=windows GOARCH=amd64
131+
mv build/zip/*.zip release
132+
133+
# release_deb creates debian releases.
134+
release_deb: binary_deb
135+
mkdir -p release
136+
mv build/deb/*.deb release
137+
138+
# release_rpm creates rpm releases.
139+
release_rpm: binary_rpm
140+
mkdir -p release
141+
mv build/rpm/RPMS/*/*.rpm release
142+
143+
# release creates all release packages.
144+
# Example: make distclean release VERSION=1.0
145+
release: release_deb release_rpm release_tar release_zip
146+
147+
# Removes build related files.
148+
clean:
149+
rm -rf build
150+
151+
distclean: clean
152+
rm -rf release
153+
154+
.PHONY: $(TOOLS)

build_tarballs.sh

Lines changed: 0 additions & 39 deletions
This file was deleted.

debian/README.Debian

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
A set of tools to work with the feeds (vulnerabilities, CPE dictionary etc.) distributed by National Vulnerability Database (NVD)
1+
A set of tools to work with the feeds (vulnerabilities, CPE dictionary etc.) distributed by National Vulnerability Database (NVD).

debian/control

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Source: nvdtools
22
Section: utils
33
Priority: extra
4-
Maintainer: Alexandre Fiori <[email protected]>
4+
Maintainer: Alexandre Fiori <[email protected]>
55
Build-Depends: debhelper (>=9)
66
Standards-Version: 3.9.6
77
Homepage: https://github.com/facebookincubator/nvdtools/
@@ -10,4 +10,4 @@ Package: nvdtools
1010
Architecture: any
1111
Multi-Arch: foreign
1212
Depends: ${misc:Depends}, ${shlibs:Depends}
13-
Description: A set of tools to work with the feeds (vulnerabilities, CPE dictionary etc.) distributed by National Vulnerability Database (NVD)
13+
Description: A set of tools to work with the feeds (vulnerabilities, CPE dictionary etc.) distributed by National Vulnerability Database (NVD).

0 commit comments

Comments
 (0)