Skip to content

Commit

Permalink
Merge pull request #10 from VerizonMedia/docker-images-versioning
Browse files Browse the repository at this point in the history
Support overriding image by using --image flag
  • Loading branch information
edeNFed authored Aug 29, 2020
2 parents 7914f36 + 74ccef8 commit f014fd2
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 12 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@master
- name: Set env
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Build JVM Docker Image
uses: docker/build-push-action@v1
with:
dockerfile: 'agent/Dockerfile'
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: verizondigital/kubectl-flame
tags: ${{ steps.vars.outputs.tag }}-jvm
- name: Build JVM Alpine Docker Image
uses: docker/build-push-action@v1
with:
dockerfile: 'agent/Dockerfile.alpine'
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASSWORD }}
repository: verizondigital/kubectl-flame
tags: ${{ steps.vars.outputs.tag }}-jvm-alpine
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand Down
4 changes: 4 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ builds:
- arm64
- ppc64le
goarm: [6, 7]
ldflags: |
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.semver={{ .Tag }}
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.date={{ .Date }}
-X github.com/VerizonMedia/kubectl-flame/cli/cmd/version.commit={{ .Commit }}
archives:
- id: kubectl-flame-archive
name_template: |
Expand Down
11 changes: 8 additions & 3 deletions agent/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
FROM golang:1.14-buster as agentbuild
WORKDIR /go/src/github.com/VerizonMedia/kubectl-flame
ADD . /go/src/github.com/VerizonMedia/kubectl-flame
RUN go get -d -v ./...
RUN cd agent && go build -o /go/bin/agent

FROM openjdk:8 as asyncprofiler
RUN echo deb http://deb.debian.org/debian stretch-backports main > /etc/apt/sources.list.d/stretch-backports.list && \
apt-get update && \
Expand All @@ -7,8 +13,7 @@ RUN cd async-profiler && make

FROM bitnami/minideb:stretch
RUN mkdir -p /app/async-profiler/build
ADD agent /app
COPY --from=agentbuild /go/bin/agent /app
COPY --from=asyncprofiler /async-profiler/build /app/async-profiler/build
COPY --from=asyncprofiler /async-profiler/profiler.sh /app/async-profiler
CMD [ "/app/agent" ]

CMD [ "/app/agent" ]
11 changes: 8 additions & 3 deletions agent/Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
FROM golang:1.14-buster as agentbuild
WORKDIR /go/src/github.com/VerizonMedia/kubectl-flame
ADD . /go/src/github.com/VerizonMedia/kubectl-flame
RUN go get -d -v ./...
RUN cd agent && go build -o /go/bin/agent

FROM openjdk:8-alpine as asyncprofiler
RUN apk add build-base git linux-headers
RUN git clone https://github.com/edeNFed/async-profiler.git
RUN cd async-profiler && make

FROM alpine
RUN mkdir -p /app/async-profiler/build
ADD agent /app
COPY --from=agentbuild /go/bin/agent /app
COPY --from=asyncprofiler /async-profiler/build /app/async-profiler/build
COPY --from=asyncprofiler /async-profiler/profiler.sh /app/async-profiler
CMD [ "/app/agent" ]

CMD [ "/app/agent" ]
1 change: 1 addition & 0 deletions cli/cmd/data/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ type TargetDetails struct {
FileName string
Alpine bool
DryRun bool
Image string
}
21 changes: 17 additions & 4 deletions cli/cmd/kubernetes/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package kubernetes
import (
"context"
"fmt"
"github.com/VerizonMedia/kubectl-flame/cli/cmd/version"
"os"

"github.com/VerizonMedia/kubectl-flame/cli/cmd/data"
Expand All @@ -16,12 +17,11 @@ import (
"k8s.io/apimachinery/pkg/util/uuid"
)

const imageName = "verizondigital/kubectl-flame"

func LaunchFlameJob(targetPod *v1.Pod, targetDetails *data.TargetDetails, ctx context.Context) (string, *batchv1.Job, error) {
id := string(uuid.NewUUID())
imageName := "edenfed/kubectl-flame:latest"
if targetDetails.Alpine {
imageName += "-alpine"
}
imageName := getAgentImage(targetDetails)

commonMeta := metav1.ObjectMeta{
Name: fmt.Sprintf("kubectl-flame-%s", id),
Expand Down Expand Up @@ -108,6 +108,19 @@ func printJob(job *batchv1.Job) error {
return encoder.Encode(job, os.Stdout)
}

func getAgentImage(targetDetails *data.TargetDetails) string {
if targetDetails.Image != "" {
return targetDetails.Image
}

tag := fmt.Sprintf("%s-jvm", version.GetCurrent())
if targetDetails.Alpine {
tag = fmt.Sprintf("%s-alpine", tag)
}

return fmt.Sprintf("%s:%s", imageName, tag)
}

func DeleteProfilingJob(job *batchv1.Job, targetDetails *data.TargetDetails, ctx context.Context) error {
deleteStrategy := metav1.DeletePropagationForeground
return clientSet.
Expand Down
13 changes: 11 additions & 2 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package cmd
import (
"fmt"
"github.com/VerizonMedia/kubectl-flame/cli/cmd/data"
"github.com/VerizonMedia/kubectl-flame/cli/cmd/version"
"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"time"
Expand All @@ -29,6 +30,7 @@ These commands help you identify application performance issues.
)

var targetDetails data.TargetDetails
var showVersion bool

type FlameOptions struct {
configFlags *genericclioptions.ConfigFlags
Expand All @@ -54,6 +56,11 @@ func NewFlameCommand(streams genericclioptions.IOStreams) *cobra.Command {
c.SetOutput(streams.ErrOut)
},
Run: func(cmd *cobra.Command, args []string) {
if showVersion {
fmt.Fprintln(streams.Out, version.String())
return
}

if len(args) == 0 {
cmd.Help()
return
Expand All @@ -68,10 +75,12 @@ func NewFlameCommand(streams genericclioptions.IOStreams) *cobra.Command {
},
}

cmd.Flags().DurationVarP(&targetDetails.Duration, "time", "t", defaultDuration, "Enter max scan Duration")
cmd.Flags().BoolVar(&showVersion, "version", false, "Print version info")
cmd.Flags().DurationVarP(&targetDetails.Duration, "time", "t", defaultDuration, "Max scan Duration")
cmd.Flags().StringVarP(&targetDetails.FileName, "file", "f", "flamegraph.svg", "Optional file location")
cmd.Flags().BoolVar(&targetDetails.Alpine, "alpine", false, "Target image is based on Alpine")
cmd.Flags().BoolVar(&targetDetails.DryRun, "dry-run", false, "simulate profiling")
cmd.Flags().BoolVar(&targetDetails.DryRun, "dry-run", false, "Simulate profiling")
cmd.Flags().StringVar(&targetDetails.Image, "image", "", "Manually choose agent docker image")
options.configFlags.AddFlags(cmd.Flags())

return cmd
Expand Down
18 changes: 18 additions & 0 deletions cli/cmd/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package version

import "fmt"

// populated by goreleaser
var (
semver string
commit string
date string
)

func String() string {
return fmt.Sprintf("Version: %s, Commit: %s, Build Date: %s", semver, commit, date)
}

func GetCurrent() string {
return semver
}

0 comments on commit f014fd2

Please sign in to comment.