Skip to content

Commit

Permalink
perf: change docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuler committed Jul 16, 2024
1 parent bb0f968 commit 7799d58
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 67 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build-base-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Push Docker Image

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

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

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

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

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

- name: Extract commit ID
id: vars
run: echo "COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

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

- name: Create builder
run: |
docker buildx create --use --name mybuilder
docker buildx inspect --bootstrap
- name: Build and push multi-arch image
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
-f Dockerfile-base \
-t jumpserver/${{ env.REPO }}-base:${{ env.COMMIT_ID }} \
--push .
- name: Update Dockerfile
run: |
sed -i 's|-base:.* AS stage-build|-base:${{ env.COMMIT_ID }} 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 }}
15 changes: 1 addition & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,4 @@
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
FROM jumpserver/luna-base:latest AS stage-build

ARG VERSION
ENV VERSION=$VERSION
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile-base
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM node:16.20-bullseye-slim as stage-build

RUN 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.

0 comments on commit 7799d58

Please sign in to comment.