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 b24a8bd commit 343a36d
Show file tree
Hide file tree
Showing 5 changed files with 3,516 additions and 5,990 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 }}
48 changes: 8 additions & 40 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,50 +1,18 @@
FROM node:16.20-bullseye-slim AS ui-build
FROM jumpserver/lion-base:v1 AS stage-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/lion/ui

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=lion \
--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=lion \
yarn build

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

WORKDIR /opt

ARG CHECK_VERSION=v1.0.3
RUN set -ex \
&& 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 \
&& mv check /usr/local/bin/ \
&& chown root:root /usr/local/bin/check \
&& chmod 755 /usr/local/bin/check \
&& rm -f check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz

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

WORKDIR /opt/lion
COPY . .

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

COPY . .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=lion \
yarn build

WORKDIR /opt/lion/

ARG VERSION
ENV VERSION=$VERSION
Expand Down Expand Up @@ -83,7 +51,7 @@ RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=lion \

WORKDIR /opt/lion

COPY --from=ui-build /opt/lion/ui/dist ui/dist/
COPY --from=stage-build /opt/lion/ui/dist ui/dist/
COPY --from=stage-build /usr/local/bin /usr/local/bin
COPY --from=stage-build /opt/lion/lion .
COPY --from=stage-build /opt/lion/config_example.yml .
Expand Down
41 changes: 41 additions & 0 deletions Dockerfile-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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/
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 \
&& npm config set registry ${NPM_REGISTRY} \
&& yarn config set registry ${NPM_REGISTRY}

WORKDIR /opt

ARG CHECK_VERSION=v1.0.3
RUN set -ex \
&& 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 \
&& mv check /usr/local/bin/ \
&& chown root:root /usr/local/bin/check \
&& chmod 755 /usr/local/bin/check \
&& rm -f check-${CHECK_VERSION}-linux-${TARGETARCH}.tar.gz

WORKDIR /opt/lion/ui

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

ENV CGO_ENABLED=0
ENV GO111MODULE=on

WORKDIR /opt/lion

COPY go.mod go.sum ./

RUN go mod download -x
29 changes: 15 additions & 14 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,36 @@
"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.21.0",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.5.2",
"@fortawesome/vue-fontawesome": "^2.0.10",
"axios": "^1.2.1",
"axios": "^1.7.2",
"core-js": "^3.26.1",
"element-ui": "^2.15.12",
"guacamole-common-js": "1.3.0",
"vue": "^2.7.14",
"vue": "^2.7.16",
"vue-cookies": "^1.7.4",
"vue-i18n": "^8.28.2",
"vue-router": "^3.5.2",
"vuejs-logger": "^1.5.5",
"vuex": "^4.1.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.5.19",
"@vue/cli-plugin-eslint": "^4.5.19",
"@vue/cli-service": "^4.5.19",
"eslint": "^7.25.0",
"eslint-plugin-vue": "^9.8.0",
"vue-template-compiler": "^2.6.11"
"@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": {
"root": true,
Expand Down
Loading

0 comments on commit 343a36d

Please sign in to comment.