Skip to content

Commit

Permalink
perf: change Docker build workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jul 19, 2024
1 parent b4d8f9d commit 06e2ef5
Show file tree
Hide file tree
Showing 5 changed files with 3,291 additions and 5,713 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Build and Push Base Image

on:
push:
paths:
- 'go.mod'
- 'Dockerfile-base'
- 'package.json'
- 'yarn.lock'

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract date
id: vars
run: echo "IMAGE_TAG=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV

- name: Extract repository name
id: repo
run: echo "REPO=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Build and push multi-arch image
uses: docker/build-push-action@v6
with:
platforms: linux/amd64,linux/arm64
push: true
file: Dockerfile-base
tags: jumpserver/${{ env.REPO }}-base:${{ env.IMAGE_TAG }}

- name: Update Dockerfile
run: |
sed -i 's|-base:.* AS stage-build|-base:${{ env.IMAGE_TAG }} AS stage-build|' Dockerfile
- name: Commit changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add Dockerfile
git commit -m "perf: Update Dockerfile with new base image tag"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
98 changes: 5 additions & 93 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,72 +1,10 @@
FROM redis:6.2-bullseye AS redis

FROM node:16.20-bullseye-slim AS ui-build
ARG TARGETARCH
ARG NPM_REGISTRY="https://registry.npmmirror.com"
ENV NPM_REGISTY=$NPM_REGISTRY

RUN set -ex \
&& npm config set registry ${NPM_REGISTRY} \
&& yarn config set registry ${NPM_REGISTRY}

WORKDIR /opt/koko/ui

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=koko \
--mount=type=bind,source=ui/package.json,target=package.json \
--mount=type=bind,source=ui/yarn.lock,target=yarn.lock \
yarn install

ADD ui .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=koko \
yarn build

FROM golang:1.22-bullseye AS stage-build
LABEL stage=stage-build
ARG TARGETARCH

RUN set -ex \
&& echo "no" | dpkg-reconfigure dash

WORKDIR /opt

ARG HELM_VERSION=v3.14.3
ARG KUBECTL_VERSION=v1.29.3
ARG CHECK_VERSION=v1.0.3
ARG USQL_VERSION=v0.0.1
RUN set -ex \
&& mkdir -p /opt/koko/bin \
&& wget -O kubectl.tar.gz https://dl.k8s.io/${KUBECTL_VERSION}/kubernetes-client-linux-${TARGETARCH}.tar.gz \
&& tar -xf kubectl.tar.gz --strip-components=3 -C /opt/koko/bin/ kubernetes/client/bin/kubectl \
&& mv /opt/koko/bin/kubectl /opt/koko/bin/rawkubectl \
&& wget https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz --strip-components=1 -C /opt/koko/bin/ linux-${TARGETARCH}/helm \
&& mv /opt/koko/bin/helm /opt/koko/bin/rawhelm \
&& wget https://github.com/jumpserver-dev/healthcheck/releases/download/${CHECK_VERSION}/check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz -C /opt/koko/bin/ \
&& wget https://github.com/jumpserver-dev/usql/releases/download/${USQL_VERSION}/usql-${USQL_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf usql-${USQL_VERSION}-linux-${TARGETARCH}.tar.gz --strip-components=1 -C /opt/koko/bin/ \
&& wget -O /opt/koko/.kubectl_aliases https://github.com/ahmetb/kubectl-aliases/raw/master/.kubectl_aliases \
&& chmod 755 /opt/koko/bin/* \
&& chown root:root /opt/koko/bin/* \
&& rm -f *.tar.gz

ARG GOPROXY=https://goproxy.io
ENV CGO_ENABLED=0
ENV GO111MODULE=on

FROM jumpserver/koko-base:20240718_083913 AS stage-build
WORKDIR /opt/koko

RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked,id=koko \
--mount=type=bind,source=go.mod,target=go.mod \
--mount=type=bind,source=go.sum,target=go.sum \
go mod download

ARG TARGETARCH
COPY . .

COPY --from=ui-build /opt/koko/ui/dist ui/dist

ARG VERSION
ENV VERSION=$VERSION
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=koko \
cd ui && yarn build

RUN --mount=type=cache,target=/go/pkg/mod,sharing=locked,id=koko \
set +x \
Expand All @@ -83,32 +21,6 @@ RUN mkdir /opt/koko/release \
&& mv /opt/koko/utils/init-kubectl.sh /opt/koko/release \
&& chmod 755 /opt/koko/release/entrypoint.sh /opt/koko/release/init-kubectl.sh

ARG MONGOSH_VERSION=2.2.12
RUN set -ex \
&& mkdir -p /opt/koko/lib \
&& \
case "${TARGETARCH}" in \
amd64) \
wget https://downloads.mongodb.com/compass/mongosh-${MONGOSH_VERSION}-linux-x64.tgz \
&& tar -xf mongosh-${MONGOSH_VERSION}-linux-x64.tgz \
&& chown root:root mongosh-${MONGOSH_VERSION}-linux-x64/bin/* \
&& mv mongosh-${MONGOSH_VERSION}-linux-x64/bin/mongosh /opt/koko/bin/ \
&& mv mongosh-${MONGOSH_VERSION}-linux-x64/bin/mongosh_crypt_v1.so /opt/koko/lib/ \
&& rm -rf mongosh-${MONGOSH_VERSION}-linux-x64* \
;; \
arm64|ppc64le|s390x) \
wget https://downloads.mongodb.com/compass/mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}.tgz \
&& tar -xf mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}.tgz \
&& chown root:root mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/* \
&& mv mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/mongosh /opt/koko/bin/ \
&& mv mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/mongosh_crypt_v1.so /opt/koko/lib/ \
&& rm -rf mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}* \
;; \
*) \
echo "Unsupported architecture: ${TARGETARCH}" \
;; \
esac

FROM debian:bullseye-slim
ARG TARGETARCH
ENV LANG=en_US.UTF-8
Expand All @@ -130,10 +42,10 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=koko \
&& sed -i "s@# export @export @g" ~/.bashrc \
&& sed -i "s@# alias @alias @g" ~/.bashrc

COPY --from=redis /usr/local/bin/redis-cli /usr/local/bin/redis-cli

WORKDIR /opt/koko

COPY --from=stage-build /usr/local/bin/redis-cli /usr/local/bin/redis-cli
COPY --from=stage-build /opt/koko/.kubectl_aliases /opt/kubectl-aliases/.kubectl_aliases
COPY --from=stage-build /opt/koko/bin /usr/local/bin
COPY --from=stage-build /opt/koko/lib /usr/local/lib
Expand Down
86 changes: 86 additions & 0 deletions Dockerfile-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
FROM redis:6.2-bullseye AS redis-stage
FROM golang:1.22-bullseye AS stage-go-build

FROM node:20.15-bullseye
COPY --from=stage-go-build /usr/local/go/ /usr/local/go/
COPY --from=stage-go-build /go/ /go/
COPY --from=redis-stage /usr/local/bin/redis-cli /usr/local/bin/redis-cli
ENV GOPATH=/go
ENV PATH=/go/bin:/usr/local/go/bin:$PATH
ARG TARGETARCH
ARG NPM_REGISTRY="https://registry.npmmirror.com"
ENV NPM_REGISTY=$NPM_REGISTRY
RUN set -ex \
&& echo "no" | dpkg-reconfigure dash
RUN set -ex \
&& npm config set registry ${NPM_REGISTRY} \
&& yarn config set registry ${NPM_REGISTRY}

WORKDIR /opt

ARG HELM_VERSION=v3.14.3
ARG KUBECTL_VERSION=v1.29.3
ARG CHECK_VERSION=v1.0.3
ARG USQL_VERSION=v0.0.1
RUN set -ex \
&& mkdir -p /opt/koko/bin \
&& wget -O kubectl.tar.gz https://dl.k8s.io/${KUBECTL_VERSION}/kubernetes-client-linux-${TARGETARCH}.tar.gz \
&& tar -xf kubectl.tar.gz --strip-components=3 -C /opt/koko/bin/ kubernetes/client/bin/kubectl \
&& mv /opt/koko/bin/kubectl /opt/koko/bin/rawkubectl \
&& wget https://get.helm.sh/helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf helm-${HELM_VERSION}-linux-${TARGETARCH}.tar.gz --strip-components=1 -C /opt/koko/bin/ linux-${TARGETARCH}/helm \
&& mv /opt/koko/bin/helm /opt/koko/bin/rawhelm \
&& wget https://github.com/jumpserver-dev/healthcheck/releases/download/${CHECK_VERSION}/check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz -C /opt/koko/bin/ \
&& wget https://github.com/jumpserver-dev/usql/releases/download/${USQL_VERSION}/usql-${USQL_VERSION}-linux-${TARGETARCH}.tar.gz \
&& tar -xf usql-${USQL_VERSION}-linux-${TARGETARCH}.tar.gz --strip-components=1 -C /opt/koko/bin/ \
&& wget -O /opt/koko/.kubectl_aliases https://github.com/ahmetb/kubectl-aliases/raw/master/.kubectl_aliases \
&& chmod 755 /opt/koko/bin/* \
&& chown root:root /opt/koko/bin/* \
&& rm -f *.tar.gz



WORKDIR /opt/koko

ARG MONGOSH_VERSION=2.2.12
RUN set -ex \
&& mkdir -p /opt/koko/lib \
&& \
case "${TARGETARCH}" in \
amd64) \
wget https://downloads.mongodb.com/compass/mongosh-${MONGOSH_VERSION}-linux-x64.tgz \
&& tar -xf mongosh-${MONGOSH_VERSION}-linux-x64.tgz \
&& chown root:root mongosh-${MONGOSH_VERSION}-linux-x64/bin/* \
&& mv mongosh-${MONGOSH_VERSION}-linux-x64/bin/mongosh /opt/koko/bin/ \
&& mv mongosh-${MONGOSH_VERSION}-linux-x64/bin/mongosh_crypt_v1.so /opt/koko/lib/ \
&& rm -rf mongosh-${MONGOSH_VERSION}-linux-x64* \
;; \
arm64|ppc64le|s390x) \
wget https://downloads.mongodb.com/compass/mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}.tgz \
&& tar -xf mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}.tgz \
&& chown root:root mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/* \
&& mv mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/mongosh /opt/koko/bin/ \
&& mv mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}/bin/mongosh_crypt_v1.so /opt/koko/lib/ \
&& rm -rf mongosh-${MONGOSH_VERSION}-linux-${TARGETARCH}* \
;; \
*) \
echo "Unsupported architecture: ${TARGETARCH}" \
;; \
esac

WORKDIR /opt/koko/ui

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=koko \
--mount=type=bind,source=ui/package.json,target=package.json \
--mount=type=bind,source=ui/yarn.lock,target=yarn.lock \
yarn install

WORKDIR /opt/koko/

ENV CGO_ENABLED=0
ENV GO111MODULE=on

COPY go.mod go.sum ./

RUN go mod download -x
26 changes: 13 additions & 13 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"fix": "vue-cli-service lint --fix"
"serve": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service serve",
"build": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service build",
"lint": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service lint",
"fix": "NODE_OPTIONS=--openssl-legacy-provider vue-cli-service lint --fix"
},
"dependencies": {
"@babel/core": "^7.20.5",
"@babel/eslint-parser": "^7.19.1",
"@babel/core": "^7.24.9",
"@babel/eslint-parser": "^7.24.7",
"@babel/plugin-proposal-optional-chaining": "^7.18.9",
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/vue-fontawesome": "^2.0.10",
"axios": "^1.7.2",
"core-js": "^3.26.1",
"core-js": "^3.37.1",
"element-ui": "^2.15.12",
"nora-zmodemjs": "^1.1.1",
"semver": "6.3.1",
"v-contextmenu": "^2.9.0",
"vue": "^2.7.14",
"vue": "^2.7.16",
"vue-cookies": "^1.7.4",
"vue-i18n": "^8.25.0",
"vue-router": "^3.5.2",
Expand All @@ -34,11 +34,11 @@
"xterm-theme": "^1.1.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.19",
"@vue/cli-plugin-eslint": "^4.5.19",
"@vue/cli-service": "^4.5.19",
"eslint": "^6.8.0",
"eslint-plugin-vue": "^9.8.0",
"@vue/cli-plugin-babel": "^5.0.8",
"@vue/cli-plugin-eslint": "^5.0.8",
"@vue/cli-service": "^5.0.8",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^9.27.0",
"vue-template-compiler": "^2.7.14"
},
"eslintConfig": {
Expand Down
Loading

0 comments on commit 06e2ef5

Please sign in to comment.