Skip to content

Commit

Permalink
perf: change docker build (#1122)
Browse files Browse the repository at this point in the history
* perf: change docker build

* perf: node version

* perf: Update Dockerfile with new base image tag

---------

Co-authored-by: ibuler <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 23, 2024
1 parent b110be1 commit b13559c
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 71 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:
- 'package.json'
- 'package-lock.json'
- 'yarn.lock'
- 'Dockerfile-base'

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
tags: jumpserver/${{ env.REPO }}-base:${{ env.IMAGE_TAG }}
file: Dockerfile-base

- 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 }}
19 changes: 3 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
FROM node:16.20-bullseye-slim AS stage-build
ARG TARGETARCH
ARG NPM_REGISTRY="https://registry.npmmirror.com"

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

WORKDIR /data

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=luna \
--mount=type=bind,source=package.json,target=package.json \
--mount=type=bind,source=yarn.lock,target=yarn.lock \
yarn install
# Use base image to build the project avoid npm install every time
FROM jumpserver/luna-base:20240717_134816 AS stage-build

ARG VERSION
ENV VERSION=$VERSION

ADD . /data

RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=luna \
sed -i "s@version =.*;@version = '${VERSION}';@g" src/environments/environment.prod.ts \
RUN sed -i "s@version =.*;@version = '${VERSION}';@g" src/environments/environment.prod.ts \
&& yarn build \
&& cp -R src/assets/i18n luna/

Expand Down
8 changes: 8 additions & 0 deletions Dockerfile-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:20.15-bullseye-slim

WORKDIR /data

COPY package.json yarn.lock ./
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn,sharing=locked,id=luna \
yarn install

4 changes: 0 additions & 4 deletions deploy/Dockerfile

This file was deleted.

17 changes: 0 additions & 17 deletions deploy/build.yaml

This file was deleted.

4 changes: 0 additions & 4 deletions deploy/deploy.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions deploy/docker_build.sh

This file was deleted.

18 changes: 0 additions & 18 deletions deploy/publish.sh

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"license": "GPLv3",
"scripts": {
"ng": "ng",
"start": "ng serve --hmr --proxy-config proxy.conf.json --host 0.0.0.0 --base-href=/luna/ --disable-host-check",
"build": "ng build --prod --base-href=/luna/ --output-path 'luna'",
"start": "NODE_OPTIONS=--openssl-legacy-provider ng serve --hmr --proxy-config proxy.conf.json --host 0.0.0.0 --base-href=/luna/ --disable-host-check",
"build": "NODE_OPTIONS=--openssl-legacy-provider ng build --prod --base-href=/luna/ --output-path 'luna'",
"extract": "ngx-translate-extract --input ./src --output ./src/assets/i18n/*.json --sort --format namespaced-json",
"test": "ng test",
"lint": "ng lint",
Expand Down

0 comments on commit b13559c

Please sign in to comment.