diff --git a/.dockerignore b/.dockerignore index 8527b7e0e..31721a18d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,4 @@ .git bin/* +!bin/mysql-operator_linux_amd64 +!bin/mysql-operator-sidecar_linux_amd64 diff --git a/Makefile b/Makefile index f6bc1846c..86c2f9656 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ IMAGE_NAME := mysql-operator SIDECAR_IMAGE_NAME := mysql-operator-sidecar BUILD_TAG := build IMAGE_TAGS := $(APP_VERSION) +PKG_NAME := github.com/presslabs/mysql-operator BINDIR := $(PWD)/bin KUBEBUILDER_VERSION ?= 1.0.7 @@ -33,6 +34,18 @@ build: generate fmt vet go build -o bin/mysql-operator github.com/presslabs/mysql-operator/cmd/mysql-operator go build -o bin/mysql-operator-sidecar github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar +# skaffold build +bin/mysql-operator_linux_amd64: $(shell hack/development/related-go-files.sh $(PKG_NAME) cmd/mysql-operator/main.go) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/mysql-operator_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator + +bin/mysql-operator-sidecar_linux_amd64: $(shell hack/development/related-go-files.sh $(PKG_NAME) cmd/mysql-operator-sidecar/main.go) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o bin/mysql-operator-sidecar_linux_amd64 github.com/presslabs/mysql-operator/cmd/mysql-operator-sidecar + +skaffold-build: bin/mysql-operator_linux_amd64 bin/mysql-operator-sidecar_linux_amd64 + +skaffold-run: skaffold-build + skaffold run + # Run against the configured Kubernetes cluster in ~/.kube/config run: generate fmt vet go run ./cmd/mysql-operator/main.go diff --git a/hack/development/Dockerfile.operator b/hack/development/Dockerfile.operator new file mode 100644 index 000000000..83d242205 --- /dev/null +++ b/hack/development/Dockerfile.operator @@ -0,0 +1,8 @@ +FROM scratch + +# set expiration time for dev images +# https://support.coreos.com/hc/en-us/articles/115001384693-Tag-Expiration +LABEL quay.expires-after=2d + +COPY ./bin/mysql-operator_linux_amd64 /mysql-operator +ENTRYPOINT ["/mysql-operator"] diff --git a/hack/development/Dockerfile.sidecar b/hack/development/Dockerfile.sidecar new file mode 100644 index 000000000..db64a0f54 --- /dev/null +++ b/hack/development/Dockerfile.sidecar @@ -0,0 +1,32 @@ +# Copy the mysql-operator-sidecar into it's own image +FROM debian:stretch as sidecar + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + apt-transport-https ca-certificates wget \ + gnupg1 dirmngr \ + && rm -rf /var/lib/apt/lists/* + +RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 9334A25F8507EFA5 + +RUN echo 'deb https://repo.percona.com/apt stretch main' > /etc/apt/sources.list.d/percona.list + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + percona-toolkit percona-xtrabackup-24 unzip \ + && wget https://github.com/maxbube/mydumper/releases/download/v0.9.5/mydumper_0.9.5-2.stretch_amd64.deb \ + && dpkg -i mydumper_0.9.5-2.stretch_amd64.deb \ + && rm -rf mydumper_0.9.5-2.stretch_amd64.deb /var/lib/apt/lists/* \ + && wget https://downloads.rclone.org/rclone-current-linux-amd64.zip \ + && unzip rclone-current-linux-amd64.zip \ + && mv rclone-*-linux-amd64/rclone /usr/local/bin/ \ + && rm -rf rclone-*-linux-amd64 rclone-current-linux-amd64.zip \ + && chmod 755 /usr/local/bin/rclone + +# set expiration time for dev images +# https://support.coreos.com/hc/en-us/articles/115001384693-Tag-Expiration +LABEL quay.expires-after=2d + +COPY ./hack/docker/sidecar-entrypoint.sh /usr/local/bin/sidecar-entrypoint.sh +COPY ./bin/mysql-operator-sidecar_linux_amd64 /usr/local/bin/mysql-operator-sidecar +ENTRYPOINT ["/usr/local/bin/sidecar-entrypoint.sh"] diff --git a/hack/development/dev-values.yaml b/hack/development/dev-values.yaml new file mode 100644 index 000000000..11422f1f8 --- /dev/null +++ b/hack/development/dev-values.yaml @@ -0,0 +1,9 @@ +extraArgs: + - --debug + +installCRDs: false + +orchestrator: + topologyPassword: password1 + antiAffinity: soft + replicas: 1 diff --git a/hack/development/related-go-files.sh b/hack/development/related-go-files.sh new file mode 100755 index 000000000..44622e32d --- /dev/null +++ b/hack/development/related-go-files.sh @@ -0,0 +1,7 @@ +#!/bin/bash +# This command outputs a list of go files on which the given go file depends on +# Example: related-go-files.sh + +set -e + +go list -f '{{ join .Deps "\n" }}' $2 | grep 'pkg' | grep -v 'vendor' | sed -e "s|^$1/||" | xargs -I % find % -name "*.go" -maxdepth 1 -type f 2>/dev/null diff --git a/skaffold.yaml b/skaffold.yaml index 77f899fc4..71e9a4ca6 100644 --- a/skaffold.yaml +++ b/skaffold.yaml @@ -3,9 +3,11 @@ kind: Config build: artifacts: - image: quay.io/presslabs/mysql-operator + docker: + dockerfile: hack/development/Dockerfile.operator - image: quay.io/presslabs/mysql-operator-sidecar docker: - dockerfile: Dockerfile.sidecar + dockerfile: hack/development/Dockerfile.sidecar local: push: true deploy: @@ -14,7 +16,7 @@ deploy: - name: test chartPath: hack/charts/mysql-operator valuesFiles: - - hack/dev-values.yaml + - hack/development/dev-values.yaml values: image: quay.io/presslabs/mysql-operator sidecarImage: quay.io/presslabs/mysql-operator-sidecar