Skip to content

Commit 2f70b51

Browse files
authored
dropgz: self extracting gz installer and cni dropper dockerfile
Signed-off-by: Evan Baker <rbtr@users.noreply.github.com>
1 parent b27fb6c commit 2f70b51

File tree

16 files changed

+522
-30
lines changed

16 files changed

+522
-30
lines changed

.github/dependabot.yaml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,21 @@ updates:
4747
- "azure/azure-sdn-members"
4848
commit-message:
4949
prefix: "deps"
50+
- package-ecosystem: "gomod"
51+
directory: "/dropgz"
52+
schedule:
53+
interval: "daily"
54+
assignees:
55+
- "matmerr"
56+
- "rbtr"
57+
commit-message:
58+
prefix: "deps"
5059
- package-ecosystem: "gomod"
5160
directory: "/zapai"
5261
schedule:
5362
interval: "daily"
5463
assignees:
5564
- "matmerr"
5665
- "rbtr"
57-
reviewers:
58-
- "azure/azure-sdn-members"
5966
commit-message:
6067
prefix: "deps"

.pipelines/pipeline.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,22 @@ stages:
150150
name: "$(BUILD_POOL_NAME_DEFAULT)"
151151
strategy:
152152
matrix:
153-
cni_manager_linux_amd64:
153+
acncli_linux_amd64:
154154
arch: amd64
155155
os: linux
156-
name: cni-manager
157-
cni_manager_linux_arm64:
156+
name: acncli
157+
acncli_linux_arm64:
158158
arch: arm64
159159
os: linux
160-
name: cni-manager
160+
name: acncli
161+
cni_dropgz_linux_amd64:
162+
arch: amd64
163+
os: linux
164+
name: cni-dropgz
165+
cni_dropgz_linux_arm64:
166+
arch: arm64
167+
os: linux
168+
name: cni-dropgz
161169
cns_linux_amd64:
162170
arch: amd64
163171
os: linux
@@ -216,9 +224,12 @@ stages:
216224
name: "$(BUILD_POOL_NAME_DEFAULT)"
217225
strategy:
218226
matrix:
219-
cni-manager:
227+
acncli:
220228
name: cni-manager
221229
platforms: linux/amd64 linux/arm64
230+
cni_dropgz:
231+
name: cni-dropgz
232+
platforms: linux/amd64 linux/arm64
222233
cns:
223234
name: cns
224235
platforms: linux/amd64 linux/arm64 windows/amd64

Makefile

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ CNI_BAREMETAL_ARCHIVE_NAME = azure-vnet-cni-baremetal-$(GOOS)-$(GOARCH)-$(VERSIO
8181
CNS_ARCHIVE_NAME = azure-cns-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
8282
NPM_ARCHIVE_NAME = azure-npm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
8383
NPM_IMAGE_INFO_FILE = azure-npm-$(VERSION).txt
84-
CNI_IMAGE_ARCHIVE_NAME = azure-cni-manager-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
85-
CNI_IMAGE_INFO_FILE = azure-cni-manager-$(VERSION).txt
84+
CNIDROPGZ_IMAGE_ARCHIVE_NAME = cni-dropgz-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
85+
CNIDROPGZ_IMAGE_INFO_FILE = cni-dropgz-$(VERSION).txt
8686
CNS_IMAGE_INFO_FILE = azure-cns-$(VERSION).txt
8787

8888
# Docker libnetwork (CNM) plugin v2 image parameters.
8989
CNM_PLUGIN_IMAGE ?= microsoft/azure-vnet-plugin
9090
CNM_PLUGIN_ROOTFS = azure-vnet-plugin-rootfs
9191

92-
VERSION ?= $(shell git describe --tags --always --dirty)
92+
VERSION ?= $(shell git describe --exclude "zapai*" --tags --always --dirty)
9393

9494
# Default target
9595
all-binaries-platforms: ## Make all platform binaries
@@ -101,7 +101,7 @@ all-binaries-platforms: ## Make all platform binaries
101101

102102
# OS specific binaries/images
103103
ifeq ($(GOOS),linux)
104-
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-npm
104+
all-binaries: acncli azure-cnm-plugin azure-cni-plugin azure-cns azure-npm
105105
all-images: npm-image cns-image cni-manager-image
106106
else
107107
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns azure-npm
@@ -156,9 +156,10 @@ azure-npm-binary:
156156

157157
##@ Containers
158158

159-
CNI_IMAGE = azure-cni-manager
160-
CNS_IMAGE = azure-cns
161-
NPM_IMAGE = azure-npm
159+
ACNCLI_IMAGE = acncli
160+
CNIDROPGZ_IMAGE = cni-dropgz
161+
CNS_IMAGE = azure-cns
162+
NPM_IMAGE = azure-npm
162163

163164
TAG ?= $(VERSION)
164165
IMAGE_REGISTRY ?= acnpublic.azurecr.io
@@ -213,33 +214,60 @@ container-info: # util target to write container info file. do not invoke direct
213214
sudo chown -R $$(whoami) $(IMAGE_DIR)
214215
sudo chmod -R 777 $(IMAGE_DIR)
215216

216-
cni-manager-image-name: # util target to print the CNI manager image name.
217-
@echo $(CNI_IMAGE)
217+
acncli-image-name: # util target to print the CNI manager image name.
218+
@echo $(ACNCLI_IMAGE)
218219

219-
cni-manager-image: ## build cni-manager container image.
220+
acncli-image: ## build cni-manager container image.
220221
$(MAKE) containerize-$(CONTAINER_BUILDER) \
221222
PLATFORM=$(PLATFORM) \
222223
DOCKERFILE=tools/acncli/Dockerfile \
223224
REGISTRY=$(IMAGE_REGISTRY) \
224-
IMAGE=$(CNI_IMAGE) \
225-
EXTRA_BUILD_ARGS='--build-arg PLATFORM=$(OS)_$(ARCH)' \
225+
IMAGE=$(ACNCLI_IMAGE) \
226226
TAG=$(TAG)
227227

228-
cni-manager-image-info: # util target to write cni-manager container info file.
229-
$(MAKE) container-info IMAGE=$(CNI_IMAGE) TAG=$(TAG) FILE=$(CNI_IMAGE_INFO_FILE)
228+
acncli-image-info: # util target to write cni-manager container info file.
229+
$(MAKE) container-info IMAGE=$(ACNCLI_IMAGE) TAG=$(TAG) FILE=$(ACNCLI_IMAGE_INFO_FILE)
230230

231-
cni-manager-image-push: ## push cni-manager container image.
231+
acncli-image-push: ## push cni-manager container image.
232232
$(MAKE) container-push \
233233
PLATFORM=$(PLATFORM) \
234234
REGISTRY=$(IMAGE_REGISTRY) \
235-
IMAGE=$(CNI_IMAGE) \
235+
IMAGE=$(ACNCLI_IMAGE) \
236236
TAG=$(TAG)
237237

238-
cni-manager-image-pull: ## pull cni-manager container image.
238+
acncli-image-pull: ## pull cni-manager container image.
239239
$(MAKE) container-pull \
240240
PLATFORM=$(PLATFORM) \
241241
REGISTRY=$(IMAGE_REGISTRY) \
242-
IMAGE=$(CNI_IMAGE) \
242+
IMAGE=$(ACNCLI_IMAGE) \
243+
TAG=$(TAG)
244+
245+
cni-dropgz-image-name: # util target to print the CNI dropgz image name.
246+
@echo $(CNIDROPGZ_IMAGE)
247+
248+
cni-dropgz-image: ## build cni-dropgz container image.
249+
$(MAKE) containerize-$(CONTAINER_BUILDER) \
250+
PLATFORM=$(PLATFORM) \
251+
DOCKERFILE=dropgz/build/cni.Dockerfile \
252+
REGISTRY=$(IMAGE_REGISTRY) \
253+
IMAGE=$(CNIDROPGZ_IMAGE) \
254+
TAG=$(TAG)
255+
256+
cni-dropgz-image-info: # util target to write cni-dropgz container info file.
257+
$(MAKE) container-info IMAGE=$(CNIDROPGZ_IMAGE) TAG=$(TAG) FILE=$(CNIDROPGZ_IMAGE_INFO_FILE)
258+
259+
cni-dropgz-image-push: ## push cni-dropgz container image.
260+
$(MAKE) container-push \
261+
PLATFORM=$(PLATFORM) \
262+
REGISTRY=$(IMAGE_REGISTRY) \
263+
IMAGE=$(CNIDROPGZ_IMAGE) \
264+
TAG=$(TAG)
265+
266+
cni-dropgz-image-pull: ## pull cni-dropgz container image.
267+
$(MAKE) container-pull \
268+
PLATFORM=$(PLATFORM) \
269+
REGISTRY=$(IMAGE_REGISTRY) \
270+
IMAGE=$(CNIDROPGZ_IMAGE) \
243271
TAG=$(TAG)
244272

245273
cns-image-name: # util target to print the CNS image name

dropgz/build/cni.Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM mcr.microsoft.com/oss/go/microsoft/golang:1.18 AS builder
2+
ARG VERSION
3+
WORKDIR /azure-container-networking
4+
COPY . .
5+
RUN CGO_ENABLED=0 go build -a -o bin/azure-vnet -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/network/plugin/main.go
6+
RUN mv bin/* dropgz/pkg/embed/gz &&\
7+
mv cni/*.conflist dropgz/pkg/embed/gz &&\
8+
cd dropgz/pkg/embed/gz/ && sha256sum * > sum.txt
9+
RUN gzip --best --recursive dropgz/pkg/embed/gz && for f in dropgz/pkg/embed/gz/*.gz; do mv -- "$f" "${f%%.gz}"; done
10+
RUN cd dropgz && CGO_ENABLED=0 go build -a -o ../bin/dropgz -trimpath -ldflags "-X github.com/Azure/azure-container-networking/dropgz/internal/buildinfo.Version="$VERSION"" -gcflags="-dwarflocationlists=true" main.go
11+
12+
FROM scratch
13+
COPY --from=builder /etc/passwd /etc/passwd
14+
COPY --from=builder /etc/group /etc/group
15+
COPY --from=builder azure-container-networking/bin/dropgz /usr/local/bin/dropgz
16+
ENTRYPOINT [ "/usr/local/bin/dropgz" ]

dropgz/cmd/payload.go

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Azure/azure-container-networking/dropgz/pkg/embed"
7+
"github.com/Azure/azure-container-networking/dropgz/pkg/hash"
8+
"github.com/pkg/errors"
9+
"github.com/spf13/cobra"
10+
"go.uber.org/zap"
11+
)
12+
13+
// list subcommand
14+
var list = &cobra.Command{
15+
Use: "list",
16+
RunE: func(*cobra.Command, []string) error {
17+
contents, err := embed.Contents()
18+
if err != nil {
19+
return err
20+
}
21+
for _, c := range contents {
22+
fmt.Printf("\t%s\n", c)
23+
}
24+
return nil
25+
},
26+
}
27+
28+
func checksum(srcs, dests []string) error {
29+
if len(srcs) != len(dests) {
30+
return errors.Wrapf(embed.ErrArgsMismatched, "%d and %d", len(srcs), len(dests))
31+
}
32+
r, c, err := embed.Extract("sum.txt")
33+
if err != nil {
34+
return errors.Wrap(err, "failed to extract checksum file")
35+
}
36+
defer c.Close()
37+
defer r.Close()
38+
39+
checksums, err := hash.Parse(r)
40+
if err != nil {
41+
return errors.Wrap(err, "failed to parse checksums")
42+
}
43+
for i := range srcs {
44+
valid, err := checksums.Check(srcs[i], dests[i])
45+
if err != nil {
46+
return errors.Wrapf(err, "failed to validate file at %s", dests[i])
47+
}
48+
if !valid {
49+
return errors.Wrapf(err, "%s checksum validation failed", dests[i])
50+
}
51+
}
52+
return nil
53+
}
54+
55+
var (
56+
skipVerify bool
57+
outs []string
58+
)
59+
60+
// deploy subcommand
61+
var deploy = &cobra.Command{
62+
Use: "deploy",
63+
RunE: func(_ *cobra.Command, srcs []string) error {
64+
if len(outs) == 0 {
65+
outs = srcs
66+
}
67+
if len(srcs) != len(outs) {
68+
return errors.Wrapf(embed.ErrArgsMismatched, "%d files, %d outputs", len(srcs), len(outs))
69+
}
70+
log := z.With(zap.Strings("sources", srcs), zap.Strings("outputs", outs), zap.String("cmd", "deploy"))
71+
if err := embed.Deploy(log, srcs, outs); err != nil {
72+
log.Error("failed to deploy", zap.Error(err))
73+
return errors.Wrapf(err, "failed to deploy %s", srcs)
74+
}
75+
log.Info("successfully wrote files")
76+
if skipVerify {
77+
return nil
78+
}
79+
if err := checksum(srcs, outs); err != nil {
80+
log.Error("failed to verify", zap.Error(err))
81+
return err
82+
}
83+
log.Info("verified file integrity")
84+
return nil
85+
},
86+
Args: cobra.OnlyValidArgs,
87+
}
88+
89+
// verify subcommand
90+
var verify = &cobra.Command{
91+
Use: "verify",
92+
RunE: func(_ *cobra.Command, srcs []string) error {
93+
if len(outs) == 0 {
94+
outs = srcs
95+
}
96+
if len(srcs) != len(outs) {
97+
return errors.Wrapf(embed.ErrArgsMismatched, "%d sources, %d destinations", len(srcs), len(outs))
98+
}
99+
log := z.With(zap.Strings("sources", srcs), zap.String("cmd", "deploy"))
100+
if err := checksum(srcs, outs); err != nil {
101+
log.Error("failed to verify", zap.Error(err))
102+
return err
103+
}
104+
return nil
105+
},
106+
Args: cobra.OnlyValidArgs,
107+
}
108+
109+
func init() {
110+
root.AddCommand(list)
111+
112+
verify.ValidArgs, _ = embed.Contents()
113+
verify.Flags().StringSliceVarP(&outs, "output", "o", []string{}, "output file path")
114+
root.AddCommand(verify)
115+
116+
deploy.ValidArgs, _ = embed.Contents() // setting this after the command is initialized is required
117+
deploy.Flags().BoolVar(&skipVerify, "skip-verify", false, "set to disable checksum validation")
118+
deploy.Flags().StringSliceVarP(&outs, "output", "o", []string{}, "output file path")
119+
root.AddCommand(deploy)
120+
}

dropgz/cmd/root.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"os/signal"
8+
"syscall"
9+
10+
zaplogfmt "github.com/jsternberg/zap-logfmt"
11+
"github.com/spf13/cobra"
12+
"go.uber.org/zap"
13+
"go.uber.org/zap/zapcore"
14+
)
15+
16+
var (
17+
ctx context.Context
18+
z *zap.Logger
19+
)
20+
21+
// root represent the base invocation.
22+
var root = &cobra.Command{
23+
Use: "dropgz",
24+
}
25+
26+
func init() {
27+
// set up signal handlers
28+
var cancel context.CancelFunc
29+
ctx, cancel = context.WithCancel(context.Background())
30+
31+
sig := make(chan os.Signal, 1)
32+
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
33+
go func() {
34+
<-sig
35+
cancel()
36+
fmt.Println("exiting")
37+
}()
38+
39+
// bind root flags
40+
root.PersistentFlags().StringP("log-level", "v", "info", "log level [trace,debug,info,warn,error]")
41+
}
42+
43+
func Execute() {
44+
var err error
45+
zcfg := zap.NewProductionEncoderConfig()
46+
z = zap.New(zapcore.NewCore(
47+
zaplogfmt.NewEncoder(zcfg),
48+
os.Stdout,
49+
zapcore.InfoLevel,
50+
))
51+
if err != nil {
52+
os.Exit(1)
53+
}
54+
if err = root.Execute(); err != nil {
55+
z.Error("dropgz exiting", zap.Error(err))
56+
os.Exit(1)
57+
}
58+
}

dropgz/cmd/version.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/Azure/azure-container-networking/dropgz/internal/buildinfo"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
// version command.
11+
var version = &cobra.Command{
12+
Use: "version",
13+
Run: func(cmd *cobra.Command, args []string) {
14+
fmt.Println(buildinfo.Version)
15+
},
16+
}
17+
18+
func init() {
19+
root.AddCommand(version)
20+
}

0 commit comments

Comments
 (0)