Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add make all-push rule #228

Merged
merged 2 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions .github/workflows/container-image.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ jobs:
uses: docker/setup-buildx-action@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Push to Dockerhub registry
- name: Set environment variables
run: |
BRANCH=$(echo $GITHUB_REF | cut -d'/' -f3)
REPO=amazon/aws-fsx-csi-driver
if [ "$BRANCH" = "master" ]; then
TAG="latest"
REGISTRY_NAME=docker.io/amazon
BRANCH_OR_TAG=$(echo $GITHUB_REF | cut -d'/' -f3)
if [ "$BRANCH_OR_TAG" = "master" ]; then
GIT_TAG=$GITHUB_SHA
else
TAG=$BRANCH
GIT_TAG=$BRANCH_OR_TAG
fi
docker login -u ${{ secrets.DOCKERHUB_USER }} -p ${{ secrets.DOCKERHUB_TOKEN }}
docker buildx build \
-t $REPO:$TAG \
--platform=linux/arm64,linux/amd64 \
--progress plain \
--push .
echo "REGISTRY_NAME=$REGISTRY_NAME" >> $GITHUB_ENV
echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV
- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push manifest list containing amazon linux based images to Docker Hub
run: |
export REGISTRY=$REGISTRY_NAME
export TAG=$GIT_TAG
make all-push
9 changes: 2 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,10 @@

FROM --platform=$BUILDPLATFORM golang:1.16.8-stretch as builder
WORKDIR /go/src/github.com/kubernetes-sigs/aws-fsx-csi-driver

COPY . .
ARG TARGETOS
ARG TARGETARCH
RUN echo "TARGETOS:$TARGETOS, TARGETARCH:$TARGETARCH"
RUN echo "I am running on $(uname -s)/$(uname -m)"

COPY . .

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} make aws-fsx-csi-driver
RUN OS=$TARGETOS ARCH=$TARGETARCH make $TARGETOS/$TARGETARCH

FROM amazonlinux:2 AS linux-amazon
RUN yum update -y
Expand Down
87 changes: 56 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

VERSION=v0.6.0
VERSION=v0.7.1

PKG=github.com/kubernetes-sigs/aws-fsx-csi-driver
GIT_COMMIT?=$(shell git rev-parse HEAD)
Expand All @@ -24,9 +24,10 @@ GO111MODULE=on
GOPROXY=direct
GOPATH=$(shell go env GOPATH)
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GOBIN=$(shell pwd)/bin

IMAGE?=amazon/aws-fsx-csi-driver
REGISTRY?=amazon
IMAGE?=$(REGISTRY)/aws-fsx-csi-driver
TAG?=$(GIT_COMMIT)

OUTPUT_TYPE?=docker
Expand All @@ -35,15 +36,60 @@ OS?=linux
ARCH?=amd64
OSVERSION?=amazon

IMAGE_PLATFORMS?=linux/arm64,linux/amd64
ALL_OS?=linux
ALL_ARCH_linux?=amd64 arm64
ALL_OSVERSION_linux?=amazon
ALL_OS_ARCH_OSVERSION_linux=$(foreach arch, $(ALL_ARCH_linux), $(foreach osversion, ${ALL_OSVERSION_linux}, linux-$(arch)-${osversion}))

ALL_OS_ARCH_OSVERSION=$(foreach os, $(ALL_OS), ${ALL_OS_ARCH_OSVERSION_${os}})

PLATFORM?=linux/amd64,linux/arm64

# split words on hyphen, access by 1-index
word-hyphen = $(word $2,$(subst -, ,$1))

.EXPORT_ALL_VARIABLES:

.PHONY: aws-fsx-csi-driver
aws-fsx-csi-driver:
mkdir -p bin
@echo GOARCH:${GOARCH}
CGO_ENABLED=0 GOOS=linux go build -ldflags ${LDFLAGS} -o bin/aws-fsx-csi-driver ./cmd/
.PHONY: linux/$(ARCH) bin/aws-fsx-csi-driver
linux/$(ARCH): bin/aws-fsx-csi-driver
bin/aws-fsx-csi-driver: | bin
CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH) go build -ldflags ${LDFLAGS} -o bin/aws-fsx-csi-driver ./cmd/

.PHONY: all
all: all-image-docker

.PHONY: all-push
all-push:
docker buildx build \
--platform=$(PLATFORM) \
--progress=plain \
--target=$(OS)-$(OSVERSION) \
--output=type=registry \
-t=$(IMAGE):$(TAG) \
.
touch $@

.PHONY: all-image-docker
all-image-docker: $(addprefix sub-image-docker-,$(ALL_OS_ARCH_OSVERSION_linux))

sub-image-%:
$(MAKE) OUTPUT_TYPE=$(call word-hyphen,$*,1) OS=$(call word-hyphen,$*,2) ARCH=$(call word-hyphen,$*,3) OSVERSION=$(call word-hyphen,$*,4) image

.PHONY: image
image: .image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to document the targets intended to be run by command line like make all-image-docker (I guess you don't expect anyone to call make image TAG=.. OS=.. ARCH=..?). Also, all of these targets should be .PHONY, right? Lastly, might want a check for these variables to be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main userfacing ones should be make all and make all-push (which is executed by github workflow). But make image has a usecase during CI when we want to only build linux/amd64

The vars are always defaulted by ?=

And i know i can mark them phony but it's annoying to do it for every rule. in particular, the .image should not be phony because it touches a file at the end so that the same image for the same tag+os+arch is not built again

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHONY'd the rules I could in 2 nd commit xd

.image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION):
docker buildx build \
--platform=$(OS)/$(ARCH) \
--progress=plain \
--target=$(OS)-$(OSVERSION) \
--output=type=$(OUTPUT_TYPE) \
-t=$(IMAGE):$(TAG)-$(OS)-$(ARCH)-$(OSVERSION) \
.
touch $@

.PHONY: clean
clean:
rm -rf .*image-* bin/

bin /tmp/helm:
@mkdir -p $@
Expand Down Expand Up @@ -75,28 +121,7 @@ test-e2e:
GINKGO_SKIP="subPath.should.be.able.to.unmount.after.the.subpath.directory.is.deleted|\[Disruptive\]|\[Serial\]" \
./hack/e2e/run.sh

.PHONY: image
image: .image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION)
.image-$(TAG)-$(OS)-$(ARCH)-$(OSVERSION):
docker buildx build \
--platform=$(OS)/$(ARCH) \
--build-arg OS=$(OS) \
--build-arg ARCH=$(ARCH) \
--progress=plain \
--target=$(OS)-$(OSVERSION) \
--output=type=$(OUTPUT_TYPE) \
-t=$(IMAGE):$(TAG)-$(OS)-$(ARCH)-$(OSVERSION) \
.
touch $@

.PHONY: image-multi-arch--push
image-multi-arch--push:
docker buildx build \
-t $(IMAGE):latest \
--platform=$(IMAGE_PLATFORMS) \
--progress plain \
--push .

.PHONY: generate-kustomize
generate-kustomize: bin/helm
cd charts/aws-fsx-csi-driver && ../../bin/helm template kustomize . -s templates/csidriver.yaml > ../../deploy/kubernetes/base/csidriver.yaml
cd charts/aws-fsx-csi-driver && ../../bin/helm template kustomize . -s templates/node-daemonset.yaml > ../../deploy/kubernetes/base/node-daemonset.yaml
Expand Down