-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
216 lines (169 loc) · 6.07 KB
/
Earthfile
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
209
210
211
212
213
214
215
216
VERSION 0.6
FROM python:3.9-slim
WORKDIR "/root/"
all:
BUILD +safety
FOR PKG IN "prefix_list_agent" "prefix_list_agent_cli"
BUILD --build-arg PKG=$PKG +lint
BUILD --build-arg PKG=$PKG +typecheck
BUILD --build-arg PKG=$PKG +build-rpm
END
BUILD +build-swix
FOR VERSION IN "4.28.2F" "4.30.2F" "4.31.2F"
BUILD --build-arg CEOS_VERSION=$VERSION +test
END
BUILD +docs
deps:
ENV PATH="$PATH:/root/.local/bin"
RUN apt update -qq && \
apt upgrade -qqy && \
apt install -qqy git g++ swig libssl-dev zip
RUN python -m pip install \
--progress-bar off \
--upgrade pip
RUN python -m pip install \
--progress-bar off \
--no-warn-script-location \
--user \
pipenv
RUN mkdir -p src
WORKDIR "src/"
COPY Pipfile Pipfile.lock .
RUN python -m pipenv sync --dev
LABEL org.opencontainers.image.source=https://github.com/wolcomm/eos-prefix-list-agent
SAVE IMAGE --push ghcr.io/wolcomm/eos-prefix-list-agent/ci-deps:latest
safety:
BUILD +deps
FROM +deps
RUN python -m pipenv check --full-report
src:
ARG --required PKG
FROM +deps
COPY . .
WORKDIR $PKG
lint:
ARG --required PKG
FROM --build-arg PKG=$PKG +src
RUN python -m pipenv run flake8 .
typecheck:
ARG --required PKG
FROM --build-arg PKG=$PKG +src
RUN python -m pipenv run mypy --package $PKG
sdist:
ARG --required PKG
FROM --build-arg PKG=$PKG +src
COPY --dir .git/ ..
RUN python -m pipenv run python -m build --sdist --outdir dist/
SAVE ARTIFACT dist/*.tar.gz AS LOCAL dist/sdist/
build-rpm:
FROM fedora:34
WORKDIR "/root"
RUN dnf update -y
RUN dnf install -y \
# python build deps
python3 python3-devel \
python2 python2-devel \
pyproject-rpm-macros \
# rpm build tools
rpm-build rpm-devel rpmlint rpmdevtools \
# for switools
gcc-c++ swig openssl-devel zip
RUN python2 -m ensurepip
RUN python3 -m ensurepip
RUN python3 -m pip install \
--disable-pip-version-check \
--progress-bar off \
--no-warn-script-location \
--user \
pipenv
COPY Pipfile Pipfile.lock .
RUN python3 -m pipenv requirements --dev-only > requirements.txt
RUN python3 -m pip install \
--disable-pip-version-check \
--progress-bar off \
--prefix /usr \
--ignore-installed \
-r "requirements.txt"
ARG --required PKG
RUN rpmdev-setuptree
COPY packaging/rpm/$PKG.spec ./rpmbuild/SPECS/
COPY --build-arg PKG=$PKG +sdist/*.tar.gz rpmbuild/SOURCES/
RUN SDIST="$(find rpmbuild/SOURCES/ -name '*.tar.gz' | head -n1)" && \
VERSION="$(tar zxfO "$SDIST" --no-anchored PKG-INFO | grep '^Version:' | head -n1 | cut -d' ' -f2)" && \
echo -n "$VERSION" > VERSION && \
rpmbuild -ba rpmbuild/SPECS/$PKG.spec -D "_version $VERSION"
SAVE ARTIFACT VERSION
SAVE ARTIFACT rpmbuild/RPMS/**/*.rpm AS LOCAL dist/rpm/
LABEL org.opencontainers.image.source=https://github.com/wolcomm/eos-prefix-list-agent
SAVE IMAGE --push ghcr.io/wolcomm/eos-prefix-list-agent/ci-build-rpm:$PKG
build-swix:
FROM +deps
RUN mkdir -p dist rpms
FOR PKG IN "prefix_list_agent" "prefix_list_agent_cli"
BUILD --build-arg PKG=$PKG +build-rpm
COPY --build-arg PKG=$PKG +build-rpm/*.rpm rpms/
END
COPY --build-arg PKG="prefix_list_agent" +build-rpm/VERSION ./
COPY packaging/swix/manifest.yaml .
RUN SWIX="dist/eos-prefix-list-agent-$(cat VERSION).swix" && \
python -m pipenv run swix-create -i manifest.yaml "$SWIX" rpms/*.rpm
SAVE ARTIFACT dist/*.swix AS LOCAL dist/swix/
test-image:
ARG --required CEOS_VERSION
FROM workonline.azurecr.io/ceos-lab:$CEOS_VERSION
WORKDIR "/root"
RUN python3 -m ensurepip --default-pip
RUN python3 -m pip install --upgrade pip
COPY Pipfile Pipfile.lock .
RUN python3 -m pip install \
--user \
--no-warn-script-location \
--progress-bar off \
pipenv
RUN python3 -m pipenv sync --system
COPY prefix_list_agent/pyproject.toml .
COPY tests/data/startup-config /mnt/flash/
COPY --dir tests .
SAVE IMAGE --cache-from ghcr.io/wolcomm/eos-prefix-list-agent/ci-test:$CEOS_VERSION
ARG LOCAL_PACKAGE
IF [ -n "$LOCAL_PACKAGE" ]
COPY $LOCAL_PACKAGE /mnt/flash/
ELSE
COPY +build-swix/*.swix /mnt/flash/
END
RUN SWIX="$(basename $(find /mnt/flash -name '*.swix'))" && \
echo "copy flash:/${SWIX} extension:" > install-extension-script && \
echo "extension ${SWIX}" >> install-extension-script
SAVE ARTIFACT install-extension-script
LABEL org.opencontainers.image.source=https://github.com/wolcomm/eos-prefix-list-agent
SAVE IMAGE --push ghcr.io/wolcomm/eos-prefix-list-agent/ci-test:$CEOS_VERSION
test:
FROM earthly/dind:alpine
ARG --required CEOS_VERSION
BUILD --build-arg CEOS_VERSION=$CEOS_VERSION +test-image
COPY +test-image/install-extension-script .
WITH DOCKER --load test-image:latest=+test-image --build-arg CEOS_VERSION=$CEOS_VERSION
RUN docker run --detach --privileged --rm --name test test-image:latest && \
t=30; while [[ $t -gt 0 ]]; do \
echo -n "."; \
if docker exec --tty test /usr/bin/Cli -c 'show version' >/dev/null; then \
started=1 && break; \
fi; \
sleep 1; \
let t--; \
done; \
[[ $started ]] && \
docker exec --tty test Cli -p 15 -c "$(cat install-extension-script)" && \
docker exec --tty test python3 -m pytest && \
docker cp test:/root/coverage.xml ./
END
SAVE ARTIFACT coverage.xml AS LOCAL coverage.xml
docs:
FROM peaceiris/mdbook:latest
WORKDIR "/root"
COPY --dir docs .
RUN mdbook build docs/
SAVE ARTIFACT docs/book/ AS LOCAL dist/
clean:
LOCALLY
RUN rm -rf dist/ coverage.xml