Skip to content

Commit

Permalink
chore: merge to master
Browse files Browse the repository at this point in the history
Merge dev To Master
  • Loading branch information
ibuler authored Aug 14, 2020
2 parents 73fea2a + 2f63b65 commit 3feed0a
Show file tree
Hide file tree
Showing 47 changed files with 3,058 additions and 1,605 deletions.
36 changes: 18 additions & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM golang:1.12-alpine as stage-build
LABEL stage=stage-build
WORKDIR /opt/koko
ARG GOPROXY
ARG GOPROXY=https://goproxy.io
ARG KUBECTLDOWNLOADURL=https://download.jumpserver.org/public/kubectl.tar.gz
ARG ALIASESURL=http://download.jumpserver.org/public/kubectl_aliases.tar.gz
ARG VERSION
ENV GOPROXY=$GOPROXY
ENV VERSION=$VERSION
Expand All @@ -11,41 +13,39 @@ ENV GOARCH=amd64
ENV CGO_ENABLED=0

COPY . .
RUN wget "$KUBECTLDOWNLOADURL" -O kubectl.tar.gz && tar -xzf kubectl.tar.gz \
&& chmod +x kubectl && mv kubectl rawkubectl
RUN wget "$ALIASESURL" -O kubectl_aliases.tar.gz && tar -xzvf kubectl_aliases.tar.gz
RUN cd utils && sh -ixeu build.sh

FROM debian:stretch-slim
RUN sed -i 's/deb.debian.org/mirrors.163.com/g' /etc/apt/sources.list \
&& sed -i 's/security.debian.org/mirrors.163.com/g' /etc/apt/sources.list
RUN apt-get update -y \
&& apt-get install -y locales \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 \
&& apt-get install -y --no-install-recommends gnupg dirmngr openssh-client procps curl \
&& rm -rf /var/lib/apt/lists/*

RUN set -ex; \
# gpg: key 5072E1F5: public key "MySQL Release Engineering <[email protected]>" imported
key='A4A9406876FCBD3C456770C88C718D3B5072E1F5'; \
export GNUPGHOME="$(mktemp -d)"; \
( gpg --batch --keyserver p80.pool.sks-keyservers.net --recv-keys "$key" \
|| gpg --batch --keyserver hkps.pool.sks-keyservers.net --recv-keys "$key" \
|| gpg --batch --keyserver keyserver.ubuntu.com --recv-keys "$key" \
|| gpg --batch --keyserver pgp.mit.edu --recv-keys "$key" \
|| gpg --batch --keyserver keyserver.pgp.com --recv-keys "$key" ); \
gpg --batch --export "$key" > /etc/apt/trusted.gpg.d/mysql.gpg; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME"; \
apt-key list > /dev/null
ENV LANG en_US.utf8

ENV MYSQL_MAJOR 8.0
RUN echo "deb http://mirrors.tuna.tsinghua.edu.cn/mysql/apt/debian stretch mysql-${MYSQL_MAJOR}" > /etc/apt/sources.list.d/mysql.list
RUN apt-get update && apt-get install -y gdb ca-certificates mysql-community-client && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --allow-unauthenticated --no-install-recommends mysql-community-client \
&& apt-get install -y --no-install-recommends gdb ca-certificates jq iproute2 less bash-completion unzip sysstat acl net-tools iputils-ping telnet dnsutils wget vim git \
&& rm -rf /var/lib/apt/lists/*

ENV TZ Asia/Shanghai
WORKDIR /opt/koko/
COPY --from=stage-build /opt/koko/release/koko /opt/koko
COPY --from=stage-build /opt/koko/release/koko/kubectl /usr/local/bin/kubectl
COPY --from=stage-build /opt/koko/rawkubectl /usr/local/bin/rawkubectl
COPY --from=stage-build /usr/local/go/src/runtime/sys_linux_amd64.s /usr/local/go/src/runtime/sys_linux_amd64.s
COPY --from=stage-build /opt/koko/tools/coredump.sh .
COPY --from=stage-build /opt/koko/utils/coredump.sh .
COPY --from=stage-build /opt/koko/entrypoint.sh .
COPY --from=stage-build /opt/koko/utils/init-kubectl.sh .
COPY --from=stage-build /opt/koko/.kubectl_aliases /opt/kubectl-aliases/.kubectl_aliases

RUN chmod 755 entrypoint.sh
RUN chmod 755 entrypoint.sh && chmod 755 init-kubectl.sh

EXPOSE 2222 5000
CMD ["./entrypoint.sh"]
40 changes: 40 additions & 0 deletions cmd/kubectl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"os"
"os/exec"
"strings"

"github.com/jumpserver/koko/pkg/config"
"github.com/jumpserver/koko/pkg/utils"
)

const (
commandName = "rawkubectl"
envName = "K8S_ENCRYPTED_TOKEN"
)

func main() {
encryptToken := os.Getenv(envName)
var token string
if encryptToken != "" {
token, _ = utils.Decrypt(encryptToken, config.CipherKey)
}

args := os.Args[1:]
var s strings.Builder
for i := range args {
s.WriteString(args[i])
s.WriteString(" ")
}
commandPrefix := commandName
if token != "" {
commandPrefix = fmt.Sprintf("%s --token=%s", commandName, token)
}

commandString := fmt.Sprintf("%s %s", commandPrefix, s.String())
c := exec.Command("bash", "-c", commandString)
c.Stdin, c.Stdout, c.Stderr = os.Stdin, os.Stdout, os.Stderr
_ = c.Run()
}
Loading

0 comments on commit 3feed0a

Please sign in to comment.