Skip to content

Commit 7980d33

Browse files
Yongli Chenjaer-tsun
authored andcommitted
build image inside build container (#204) (#205)
1 parent 73f5aa8 commit 7980d33

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Dockerfile.build

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
FROM golang:1.10
22

3-
RUN apt-get update && apt-get install -y zip
3+
RUN apt-get update \
4+
&& apt-get install -y zip \
5+
&& apt-get install -y sudo libltdl-dev
46

57
RUN go get -d golang.org/x/sys/unix
68
RUN go get -d github.com/Microsoft/hcsshim

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ CNM_PLUGIN_ROOTFS = azure-vnet-plugin-rootfs
9999
AZURE_NPM_IMAGE = containernetworking/azure-npm
100100

101101
VERSION ?= $(shell git describe --tags --always --dirty)
102-
AZURE_NPM_VERSION = VERSION
102+
AZURE_NPM_VERSION = $(VERSION)
103103

104104
ENSURE_OUTPUT_DIR_EXISTS := $(shell mkdir -p $(OUTPUT_DIR))
105105

@@ -120,6 +120,8 @@ else
120120
all-binaries: azure-cnm-plugin azure-cni-plugin azure-cns
121121
endif
122122

123+
all-images: azure-npm-image
124+
123125
# Clean all build artifacts.
124126
.PHONY: clean
125127
clean:
@@ -146,17 +148,20 @@ $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT): $(NPMFILES)
146148
go build -v -o $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) -ldflags "-X main.version=$(VERSION) -s -w" $(NPM_DIR)/*.go
147149

148150
# Build all binaries in a container.
149-
.PHONY: all-binaries-containerized
150-
all-binaries-containerized:
151+
.PHONY: all-containerized
152+
all-containerized:
151153
pwd && ls -l
152154
docker build -f Dockerfile.build -t $(BUILD_CONTAINER_IMAGE):$(VERSION) .
153155
docker run --name $(BUILD_CONTAINER_NAME) \
156+
-v /usr/bin/docker:/usr/bin/docker \
157+
-v /var/run/docker.sock:/var/run/docker.sock \
154158
$(BUILD_CONTAINER_IMAGE):$(VERSION) \
155159
bash -c '\
156160
pwd && ls -l && \
157161
export GOOS=$(GOOS) && \
158162
export GOARCH=$(GOARCH) && \
159163
make all-binaries && \
164+
make all-images && \
160165
chown -R $(BUILD_USER):$(BUILD_USER) $(BUILD_DIR) \
161166
'
162167
docker cp $(BUILD_CONTAINER_NAME):$(BUILD_CONTAINER_REPO_PATH)/$(BUILD_DIR) $(OUTPUT_DIR)

build/build-all-containerized.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
#!/usr/bin/env bash
2-
GOOS=$1 GOARCH=$2 make all-binaries-containerized
2+
3+
BUILD_CONTAINER_NAME=acn-builder
4+
GOOS=$1
5+
GOARCH=$2
6+
7+
if [ ! "$(docker ps -q -f name=$BUILD_CONTAINER_NAME)" ]; then
8+
if [ "$(docker ps -aq -f status=exited -f name=$BUILD_CONTAINER_NAME)" ]; then
9+
docker rm -f $BUILD_CONTAINER_NAME
10+
fi
11+
fi
12+
13+
make all-containerized

0 commit comments

Comments
 (0)