Skip to content

Commit

Permalink
Add arm64 support (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
johntrimble authored Sep 25, 2020
1 parent a90f03c commit f1f237e
Show file tree
Hide file tree
Showing 12 changed files with 378 additions and 108 deletions.
55 changes: 31 additions & 24 deletions .github/workflows/operatorBuildAndDeploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,42 @@ jobs:
run: |
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
mage operator:testGenerateClient
- name: Build docker - standard and ubi images
- name: Unit Tests
run: |
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
mage operator:testGo
- name: Login to GitHub Package Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u "${{ github.actor }}" --password-stdin
- name: Login to ECR
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ECR_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_SECRET }}
run: $(aws ecr get-login --no-include-email --region us-east-1)
- name: Setup Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v3
- name: Cache Docker layers
uses: actions/cache@v2
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build and Push Docker
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator'
env:
ECR_REPO: ${{ secrets.ECR_REPO }}
PR_REF: ${{ github.event.pull_request.head.ref }}
MO_BASE_OS: 'registry.access.redhat.com/ubi7/ubi-minimal:7.8'
GITHUB_REPO_OWNER: ${{ github.repository_owner }}
run: |
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
export MO_BRANCH=${PR_REF}
else
export MO_BRANCH="master"
fi;
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
mage operator:testAndBuild
- name: Deploy to ECR
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator'
env:
MO_ECR_ID: ${{ secrets.ECR_ID }}
MO_ECR_SECRET: ${{ secrets.ECR_SECRET }}
MO_ECR_REPO: ${{ secrets.ECR_REPO }}
run: |
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
export MO_TAGS=$(cat ./build/tagsToPush.txt)
mage operator:deployToECR
- name: Deploy to GH Packages
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == 'datastax/cass-operator'
env:
MO_GH_USR: 'datastax/cass-operator'
MO_GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MO_GH_PKG_REPO: 'datastax/cass-operator/operator'
run: |
fi
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH
export MO_TAGS=$(cat ./build/tagsToPush.txt)
mage operator:deployToGHPackages
export GITHUB_REPO_URL="https://github.com/${{ github.repository }}"
./scripts/build-push-images.sh
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Docker Release

on:
push:
tags:
- 'v*.*.*'

jobs:
release_cass_operator:
name: Release Cass Operator
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Login Skopeo DockerHub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | skopeo login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin docker.io
- name: Login Skopeo ECR
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ECR_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.ECR_SECRET }}
run: aws ecr get-login-password --region us-east-1 | skopeo login -u AWS --password-stdin ${ECR_REPO}
- name: Publish to Dockerhub
env:
ECR_REPO: ${{ secrets.ECR_REPO }}
run: |
./scripts/push-release.sh
2 changes: 1 addition & 1 deletion buildsettings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ dev:
images:
- datastax/dse-server:6.8.3
- datastax/cass-config-builder:1.0.3
- datastax/cassandra-mgmtapi-3_11_7:v0.1.12
- datastax/cassandra-mgmtapi-3_11_7:v0.1.13
34 changes: 20 additions & 14 deletions mage/docker/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type DockerCmd struct {
Args []string
ConfigDir string
Input string
Env map[string]string
}

func (cmd DockerCmd) ToCliArgs() []string {
Expand Down Expand Up @@ -50,55 +51,55 @@ func FromArgsInput(args []string, in string) DockerCmd {
}

func exec(cmd DockerCmd,
withInput func(string, string, ...string) error,
withoutInput func(string, ...string) error) error {
withInput func(map[string]string, string, string, ...string) error,
withoutInput func(map[string]string, string, ...string) error) error {

var err error
args := cmd.ToCliArgs()
if cmd.Input != "" {
err = withInput("docker", cmd.Input, args...)
err = withInput(cmd.Env, "docker", cmd.Input, args...)

} else {
err = withoutInput("docker", args...)
err = withoutInput(cmd.Env, "docker", args...)
}
return err
}

func output(cmd DockerCmd,
withInput func(string, string, ...string) (string, error),
withoutInput func(string, ...string) (string, error)) (string, error) {
withInput func(map[string]string, string, string, ...string) (string, error),
withoutInput func(map[string]string, string, ...string) (string, error)) (string, error) {

var err error
var out string
args := cmd.ToCliArgs()
if cmd.Input != "" {
out, err = withInput("docker", cmd.Input, args...)
out, err = withInput(cmd.Env, "docker", cmd.Input, args...)

} else {
out, err = withoutInput("docker", args...)
out, err = withoutInput(cmd.Env, "docker", args...)
}
return out, err
}

func (cmd DockerCmd) Exec() error {
return exec(cmd, shutil.RunWithInput, shutil.Run)
return exec(cmd, shutil.RunWithEnvWithInput, shutil.RunWithEnv)
}

func (cmd DockerCmd) ExecV() error {
return exec(cmd, shutil.RunVWithInput, shutil.RunV)
return exec(cmd, shutil.RunVWithEnvWithInput, shutil.RunVWithEnv)
}

func (cmd DockerCmd) ExecVPanic() {
err := exec(cmd, shutil.RunVWithInput, shutil.RunV)
err := exec(cmd, shutil.RunVWithEnvWithInput, shutil.RunVWithEnv)
mageutil.PanicOnError(err)
}

func (cmd DockerCmd) Output() (string, error) {
return output(cmd, shutil.OutputWithInput, shutil.Output)
return output(cmd, shutil.OutputWithEnvWithInput, shutil.OutputWithEnv)
}

func (cmd DockerCmd) OutputPanic() string {
out, err := output(cmd, shutil.OutputWithInput, shutil.Output)
out, err := output(cmd, shutil.OutputWithEnvWithInput, shutil.OutputWithEnv)
mageutil.PanicOnError(err)
return out
}
Expand Down Expand Up @@ -165,7 +166,12 @@ func Build(contextDir string, targetStage string, dockerFilePath string, namesAn
args = append(args, "--build-arg")
args = append(args, x)
}
return FromArgs(args)
c := FromArgs(args)
if c.Env == nil {
c.Env = map[string]string{}
}
c.Env["DOCKER_BUILDKIT"] = "1"
return c
}

func Login(configDir string, user string, pw string, repo string) DockerCmd {
Expand Down
22 changes: 18 additions & 4 deletions mage/operator/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

const (
dockerBase = "./operator/docker/base/Dockerfile"
cassOperatorTarget = "cass-operator"
cassOperatorUbiTarget = "cass-operator-ubi"
dockerUbi = "./operator/docker/ubi/Dockerfile"
rootBuildDir = "./build"
sdkBuildDir = "operator/build"
Expand Down Expand Up @@ -376,10 +378,10 @@ func calcVersionAndTags(version FullVersion, ubiBase bool) (string, []string) {
return versionedTag, tagsToPush
}

func runDockerBuild(versionedTag string, dockerTags []string, extraBuildArgs []string, dockerfile string) {
func runDockerBuild(versionedTag string, dockerTags []string, extraBuildArgs []string, target string) {
buildArgs := []string{fmt.Sprintf("VERSION_STAMP=%s", versionedTag)}
buildArgs = append(buildArgs, extraBuildArgs...)
dockerutil.Build(".", "", dockerfile, dockerTags, buildArgs).ExecVPanic()
dockerutil.Build(".", target, dockerBase, dockerTags, buildArgs).ExecVPanic()
}

func runGoBuild(version string) {
Expand All @@ -395,6 +397,18 @@ func runGoBuild(version string) {
os.Chdir("..")
}

func PrintVersion() {
settings := cfgutil.ReadBuildSettings()
fmt.Printf("%v\n", settings.Version)
}

func PrintFullVersion() {
settings := cfgutil.ReadBuildSettings()
git := getGitData()
version := calcFullVersion(settings, git)
fmt.Printf("%v\n", version)
}

// Builds operator go code.
//
// By default, a dev version will be stamped into
Expand Down Expand Up @@ -446,13 +460,13 @@ func BuildDocker() {

//build regular docker image
versionedTag, dockerTags := calcVersionAndTags(version, false)
runDockerBuild(versionedTag, dockerTags, nil, dockerBase)
runDockerBuild(versionedTag, dockerTags, nil, cassOperatorTarget)

if baseOs := os.Getenv(EnvBaseOs); baseOs != "" {
//build ubi docker image
args := []string{fmt.Sprintf("BASE_OS=%s", baseOs)}
ubiVersionedTag, ubiDockerTags := calcVersionAndTags(version, true)
runDockerBuild(ubiVersionedTag, ubiDockerTags, args, dockerUbi)
runDockerBuild(ubiVersionedTag, ubiDockerTags, args, cassOperatorUbiTarget)
dockerTags = append(dockerTags, ubiDockerTags...)
}

Expand Down
56 changes: 48 additions & 8 deletions mage/sh/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"os/exec"
"fmt"
"strings"

"github.com/datastax/cass-operator/mage/util"
Expand All @@ -21,11 +22,16 @@ import (
// to print output, if not, output will be hidden.
// Stderr will work as normal
func Run(cmd string, args ...string) error {
return RunWithEnv(nil, cmd, args...)
}

func RunWithEnv(env map[string]string, cmd string, args ...string) error {
var output io.Writer
if mg.Verbose() {
output = os.Stdout
}
_, err := sh.Exec(nil, output, os.Stderr, cmd, args...)

_, err := sh.Exec(env, output, os.Stderr, cmd, args...)
return err
}

Expand All @@ -42,14 +48,22 @@ func RunPanic(cmd string, args ...string) {

// Run command and print any output to stdout/stderr
func RunV(cmd string, args ...string) error {
_, err := sh.Exec(nil, os.Stdout, os.Stderr, cmd, args...)
return RunVWithEnv(nil, cmd, args...)
}

func RunVWithEnv(env map[string]string, cmd string, args ...string) error {
_, err := sh.Exec(env, os.Stdout, os.Stderr, cmd, args...)
return err
}

// Run command and print any output to stdout/stderr
// Will automatically panic on error
func RunVPanic(cmd string, args ...string) {
err := RunV(cmd, args...)
RunVPanicWithEnv(nil, cmd, args...)
}

func RunVPanicWithEnv(env map[string]string, cmd string, args ...string) {
err := RunVWithEnv(env, cmd, args...)
mageutil.PanicOnError(err)
}

Expand All @@ -70,8 +84,12 @@ func RunVCapture(cmd string, args ...string) (string, string, error) {
// Returns output from stdout.
// stderr gets used as normal here
func Output(cmd string, args ...string) (string, error) {
return OutputWithEnv(nil, cmd, args...)
}

func OutputWithEnv(env map[string]string, cmd string, args ...string) (string, error) {
buf := &bytes.Buffer{}
_, err := sh.Exec(nil, buf, os.Stderr, cmd, args...)
_, err := sh.Exec(env, buf, os.Stderr, cmd, args...)
return strings.TrimSuffix(buf.String(), "\n"), err
}

Expand All @@ -83,16 +101,25 @@ func OutputPanic(cmd string, args ...string) string {
return out
}

func cmdWithStdIn(cmd string, in string, args ...string) *exec.Cmd {
func cmdWithStdIn(env map[string]string, cmd string, in string, args ...string) *exec.Cmd {
envArray := []string{}
for k, v := range env {
envArray = append(envArray, fmt.Sprintf("%s=%s", k, v))
}
c := exec.Command(cmd, args...)
c.Env = envArray
buffer := bytes.Buffer{}
buffer.Write([]byte(in))
c.Stdin = &buffer
return c
}

func RunWithInput(cmd string, in string, args ...string) error {
c := cmdWithStdIn(cmd, in, args...)
return RunWithEnvWithInput(nil, cmd, in, args...)
}

func RunWithEnvWithInput(env map[string]string, cmd string, in string, args ...string) error {
c := cmdWithStdIn(nil, cmd, in, args...)
var output io.Writer
if mg.Verbose() {
output = os.Stdout
Expand All @@ -103,17 +130,30 @@ func RunWithInput(cmd string, in string, args ...string) error {
}

func RunVWithInput(cmd string, in string, args ...string) error {
c := cmdWithStdIn(cmd, in, args...)
return RunVWithEnvWithInput(nil, cmd, in, args...)
}

func RunVWithEnvWithInput(env map[string]string, cmd string, in string, args...string) error {
c := cmdWithStdIn(env, cmd, in, args...)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
return c.Run()
}

func OutputWithInput(cmd string, in string, args ...string) (string, error) {
return OutputWithEnvWithInput(nil, cmd, in, args...)
}

func OutputWithEnvWithInput(env map[string]string, cmd string, in string, args ...string) (string, error) {
envArray := []string{}
for k, v := range env {
envArray = append(envArray, fmt.Sprintf("%s=%s", k, v))
}
c := exec.Command(cmd, args...)
c.Env = envArray
buffer := bytes.Buffer{}
buffer.Write([]byte(in))
c.Stdin = &buffer
out, err := c.Output()
return string(out), err
}
}
Loading

0 comments on commit f1f237e

Please sign in to comment.