This repository has been archived by the owner on Oct 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
208 lines (176 loc) · 9.04 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
BUILDIMAGE=local/ctnr-build:latest
LITEIDEIMAGE=local/ctnr-build:liteide
DOCKER=docker
USER=$(shell [ '${DOCKER}' = docker ] && id -u || echo 0)
DOCKERRUN=${DOCKER} run --name ctnr-build --rm -v "${REPODIR}:/work" -w /work
REPODIR=$(shell pwd)
GOPATH=${REPODIR}/build
LITEIDE_WORKSPACE=${GOPATH}/liteide-workspace
PKGNAME=github.com/mgoltzsche/ctnr
PKGRELATIVEROOT=$(shell echo /src/${PKGNAME} | sed -E 's/\/+[^\/]*/..\//g')
VENDORLOCK=${REPODIR}/vendor/ready
BINARY=ctnr
COMMIT_ID=$(shell git rev-parse HEAD)
COMMIT_TAG=$(shell git describe --exact-match ${COMMIT_ID} || echo -n "dev")
COMMIT_DATE=$(shell git show -s --format=%ci ${COMMIT_ID})
# 'apparmor' tag cannot be used for runc yet since package is not yet available in alpine:3.7
BUILDTAGS_RUNC=seccomp selinux ambient
BUILDTAGS?=containers_image_ostree_stub containers_image_storage_stub containers_image_openpgp libdm_no_deferred_remove btrfs_noversion ${BUILDTAGS_RUNC}
BUILDTAGS_STATIC=${BUILDTAGS} linux static_build exclude_graphdriver_devicemapper mgoltzsche_ctnr_libcontainer
LDFLAGS+=-X main.commit=${COMMIT_ID} -X main.version=${COMMIT_TAG} -X 'main.date=${COMMIT_DATE}'
LDFLAGS_STATIC=${LDFLAGS} -extldflags '-static'
CNI_VERSION=0.6.0
CNIGOPATH=${GOPATH}/cni
COBRA=${GOPATH}/bin/cobra
PACKAGES:=$(shell go list $(BUILDFLAGS) . | grep -v github.com/mgoltzsche/ctnr/vendor)
export PATH := dist/bin:$(PATH)
all: binary-static cni-plugins-static
binary-static: .buildimage
${DOCKERRUN} -u ${USER}:${USER} ${BUILDIMAGE} make binary BUILDTAGS="${BUILDTAGS_STATIC}" LDFLAGS="${LDFLAGS_STATIC}"
check: binary-static test-static
binary: dependencies
# Building application:
GOPATH="${GOPATH}" \
go build -o dist/bin/${BINARY} -a -ldflags "${LDFLAGS}" -tags "${BUILDTAGS}" "${PKGNAME}"
ln -sf bin/${BINARY} dist/${BINARY}.linux-amd64
generate: dependencies
GOPATH="${GOPATH}" \
go get github.com/golang/protobuf/protoc-gen-go
# GOPATH="${GOPATH}"
cd "${GOPATH}"/src/github.com/mgoltzsche/ctnr/vendor/github.com/rootless-containers/proto && \
"${GOPATH}/bin/protoc-gen-go" --go_out=. rootlesscontainers.proto
test: dependencies
# Run tests
export GOPATH="${GOPATH}"; \
go test -tags "${BUILDTAGS}" -coverprofile "${GOPATH}/coverage.out" -cover $(shell export GOPATH="${GOPATH}"; cd "${GOPATH}/src/${PKGNAME}" && go list -tags "${BUILDTAGS_STATIC}" ./... 2>/dev/null | grep -Ev '/vendor/|^${PKGNAME}/build/')
#export GOPATH="${GOPATH}"; cd "${GOPATH}/src/github.com/mgoltzsche/ctnr/image/builder" && go test -tags "${BUILDTAGS}" -run ImageBuilder
test-static: dependencies .buildimage
# Run tests using BUILDTAGS_STATIC
#export GOPATH="${GOPATH}"; \
#go test -tags "${BUILDTAGS_STATIC}" -coverprofile "${GOPATH}/coverage.out" -cover $(shell export GOPATH="${GOPATH}"; cd "${GOPATH}/src/${PKGNAME}" && go list -tags "${BUILDTAGS_STATIC}" ./... 2>/dev/null | grep -Ev '/vendor/|^${PKGNAME}/build/')
${DOCKERRUN} --privileged ${BUILDIMAGE} make test BUILDTAGS="${BUILDTAGS_STATIC}" LDFLAGS="${LDFLAGS_STATIC}"
test-coverage: test
GOPATH="${GOPATH}" go tool cover -html="${GOPATH}/coverage.out"
fmt:
# Format the go code
(find . -mindepth 1 -maxdepth 1 -type d; ls *.go) | grep -Ev '^(./vendor|./dist|./build|./.git)(/.*)?$$' | xargs -n1 gofmt -w
# TODO: Run lint per default if hints fixed
lint:
export GOPATH="${GOPATH}"; \
go get golang.org/x/lint/golint && \
"${GOPATH}/bin/golint" $(shell export GOPATH="${GOPATH}"; cd "${GOPATH}/src/${PKGNAME}" && go list -tags "${BUILDTAGS_STATIC}" ./... 2>/dev/null | grep -Ev '/vendor/|^${PKGNAME}/build/')
runc: dependencies
rm -rf "${GOPATH}/src/github.com/opencontainers/runc"
mkdir -p "${GOPATH}/src/github.com/opencontainers"
cp -r "${GOPATH}/src/${PKGNAME}/vendor/github.com/opencontainers/runc" "${GOPATH}/src/github.com/opencontainers/runc"
ln -sr "${REPODIR}/vendor" "${GOPATH}/src/github.com/opencontainers/runc/vendor"
cd "${GOPATH}/src/github.com/opencontainers/runc" && \
export GOPATH="${GOPATH}" && \
make clean && \
make BUILDTAGS="${BUILDTAGS_RUNC}" && \
cp runc "${REPODIR}/dist/bin/runc"
cni-plugins-static: .buildimage
${DOCKERRUN} ${BUILDIMAGE} make cni-plugins LDFLAGS="${LDFLAGS_STATIC}"
cni-plugins:
# Build CNI plugins
mkdir -p "${CNIGOPATH}"
wget -O "${CNIGOPATH}/cni-${CNI_VERSION}.tar.gz" "https://github.com/containernetworking/cni/archive/v${CNI_VERSION}.tar.gz"
wget -O "${CNIGOPATH}/cni-plugins-${CNI_VERSION}.tar.gz" "https://github.com/containernetworking/plugins/archive/v${CNI_VERSION}.tar.gz"
tar -xzf "${CNIGOPATH}/cni-${CNI_VERSION}.tar.gz" -C "${CNIGOPATH}"
tar -xzf "${CNIGOPATH}/cni-plugins-${CNI_VERSION}.tar.gz" -C "${CNIGOPATH}"
rm -rf "${CNIGOPATH}/src/github.com/containernetworking"
mkdir -p "${CNIGOPATH}/src/github.com/containernetworking"
mv "${CNIGOPATH}/cni-${CNI_VERSION}" "${CNIGOPATH}/src/github.com/containernetworking/cni"
mv "${CNIGOPATH}/plugins-${CNI_VERSION}" "${CNIGOPATH}/src/github.com/containernetworking/plugins"
export GOPATH="${CNIGOPATH}" && \
for TYPE in main ipam meta; do \
for CNIPLUGIN in `ls ${CNIGOPATH}/src/github.com/containernetworking/plugins/plugins/$$TYPE`; do \
(set -x; go build -o dist/cni-plugins/$$CNIPLUGIN -a -ldflags "${LDFLAGS}" github.com/containernetworking/plugins/plugins/$$TYPE/$$CNIPLUGIN) || exit 1; \
done \
done
.buildimage:
# Building build image:
${DOCKER} build -f Dockerfile --target ctnr-build -t ${BUILDIMAGE} .
build-sh: .buildimage
# Running dockerized interactive build shell
${DOCKERRUN} -ti ${BUILDIMAGE} /bin/sh
dependencies: .workspace
ifeq ($(shell [ ! -d vendor -o "${UPDATE_DEPENDENCIES}" = TRUE ] && echo 0),0)
# Fetching dependencies:
GOPATH="${GOPATH}" go get github.com/LK4D4/vndr
rm -rf "${GOPATH}/vndrtmp"
mkdir "${GOPATH}/vndrtmp"
ln -sf "${REPODIR}/vendor.conf" "${GOPATH}/vndrtmp/vendor.conf"
(cd build/vndrtmp && "${GOPATH}/bin/vndr" -whitelist='.*')
rm -rf vendor
mv "${GOPATH}/vndrtmp/vendor" vendor
else
# Skipping dependency update
endif
update-dependencies:
# Update dependencies
@make dependencies UPDATE_DEPENDENCIES=TRUE
# In case LiteIDE is running it must be restarted to apply the changes
.workspace:
# Preparing build directory:
[ -d "${GOPATH}" ] || \
(mkdir -p vendor "$(shell dirname "${GOPATH}/src/${PKGNAME}")" \
&& ln -sf "${PKGRELATIVEROOT}" "${GOPATH}/src/${PKGNAME}")
cobra: .workspace
# Build cobra CLI to manage the application's CLI
GOPATH="${GOPATH}" go get github.com/spf13/cobra/cobra
"${GOPATH}/bin/cobra"
proot:
ctnr image build --verbose --dockerfile Dockerfile --target proot --tag local/proot
ctnr bundle create -b "${GOPATH}/proot-bundle" --update local/proot
cp "${GOPATH}/proot-bundle/rootfs/proot" "${REPODIR}/dist/bin/proot"
liteide: dependencies
rm -rf "${LITEIDE_WORKSPACE}"
mkdir "${LITEIDE_WORKSPACE}"
cp -r vendor "${LITEIDE_WORKSPACE}/src"
mkdir -p "${LITEIDE_WORKSPACE}/src/${PKGNAME}"
ln -sr "${REPODIR}"/* "${LITEIDE_WORKSPACE}/src/${PKGNAME}"
(cd "${LITEIDE_WORKSPACE}/src/${PKGNAME}" && rm build vendor dist)
GOPATH="${LITEIDE_WORKSPACE}" \
BUILDFLAGS="-tags \"${BUILDTAGS}\"" \
liteide "${LITEIDE_WORKSPACE}/src/${PKGNAME}" &
################################################################
# Setup LiteIDE project using the main package's context menu: #
# - 'Build Path Configuration': #
# - Make sure 'Inherit System GOPATH' is checked! #
# - Configure BUILDFLAGS variable printed above #
# - 'Lock Build Path' to the top-level directory #
# #
# CREATE NEW TOP LEVEL PACKAGES IN THE REPOSITORY DIRECTORY #
# EXTERNALLY AND RESTART LiteIDE WITH THIS COMMAND! #
################################################################
ide: .liteideimage
# Make sure to lock the build path to the top-level directory
ctnr bundle create -b ctnr-liteide --update=true -w /work \
--mount "src=${REPODIR},dst=/work/src/github.com/mgoltzsche/ctnr" \
--mount "src=${REPODIR}/liteide.ini,dst=/root/.config/liteide/liteide.ini" \
--mount src=/etc/machine-id,dst=/etc/machine-id,opt=ro \
--mount src=/tmp/.X11-unix,dst=/tmp/.X11-unix \
--env DISPLAY=$$DISPLAY \
--env GOPATH=/work \
${LITEIDEIMAGE} \
liteide /work/src/github.com/mgoltzsche/ctnr
ctnr bundle run --verbose ctnr-liteide &
.liteideimage:
ctnr image build --dockerfile=Dockerfile --target=liteide --tag=${LITEIDEIMAGE}
LITEIDE_PKGS=g++ qt5-qttools qt5-qtbase-dev qt5-qtbase-x11 qt5-qtwebkit xkeyboard-config libcanberra-gtk3 adwaita-icon-theme ttf-dejavu
.OLD_liteideimage: .buildimage
# TODO: clean this up when --workdir and --env options are supported
ctnr image build \
--from=docker-daemon:${BUILDIMAGE} \
--author='Max Goltzsche <[email protected]>' \
--run-sh='cd / && git clone https://github.com/visualfc/liteide.git \
&& apk add --update --no-cache ${LITEIDE_PKGS} || /usr/lib/qt5/bin/qmake -help >/dev/null' \
--run-sh='cd /liteide/build && ./update_pkg.sh \
&& cd /liteide/build && QTDIR=/usr/lib/qt5 ./build_linux.sh \
&& rm -rf /usr/local/bin; ln -s /liteide/build/liteide/bin /usr/local/bin' \
--tag=${LITEIDEIMAGE}
install:
cp dist/bin/ctnr /usr/local/bin/ctnr
clean:
rm -rf ./build ./dist