Skip to content

Commit

Permalink
chore: build docker images using GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dayuy authored and Carrotzpc committed Feb 2, 2024
1 parent 256241d commit 3e43eaa
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 18 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/image_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Build image

on:
push:
branches:
- main
tags:
- 'v*'
env:
REGISTRY: docker.io
BASE_IMAGE_NAME: kubebb/component-store-base
BASE_PRO_IMAGE_NAME: kubebb/component-store-base-prod
IMAGE_NAME: kubebb/component-store
DOCKER_USER: kubebb

jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: true
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
package:
- 'package.json'
- 'pnpm-lock.yaml'
- '.npmrc'
- '.pnpmfile.cjs'
- 'packages/**/package.json'
- name: Set Variable
id: set-env
run: |
TAG=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null) || true
if [ -z "$TAG" ]; then
echo "No tag found, use v0.1.0 as default"
TAG=v0.1.0
fi
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
echo "DATE=$(TZ=Asia/Shanghai date + '%Y%m%d')" >> $GITHUB_OUTPUT
- name: Show Variable
run: echo "varibables ${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}"
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
buildkitd-flags: --debug
config-inline: |
[worker.oci]
max-parallelism = 1
- name: Login to the dockerhub Registry
uses: docker/login-action@v3
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- uses: benjlevesque/short-sha@v2.1
name: Get short commit sha
id: short-sha
- name: setting token to npmrc
run: |
echo '//dev-npm.k8s.com.cn/:_authToken="${{ secrets.NPMTOKEN }}"' > /tmp/npmrc
- name: Build and push base image
id: base-build-push
if: steps.changes.outputs.package == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: base.dockerfile
platform: linux/amd64
tags: |
${{ env.REGISTRY }}/${{ env.BASE_IMAGE_NAME }}:main
push: true
secret-files: |
"npmrc=/tmp/npmrc"
- name: Build and push base pro image
id: base-pro-build-push
if: steps.changes.outputs.package == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: pro.dockerfile
platform: linux/amd64
tags: |
${{ env.REGISTRY }}/${{ env.BASE_PRO_IMAGE_NAME }}:main
push: true
secret-files: |
"npmrc=/tmp/npmrc"
- name: Build and push
id: push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }}
${{ steps.meta.outputs.tags }}
push: true
build-args: |
BUILD_ID=${{ env.SEMREV_LABEL }}
BUILD_DATE=${{ env.BUILD_DATE }}
secret-files: |
"npmrc=/tmp/npmrc"
2 changes: 1 addition & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
registry=http://dev-npm.tenxcloud.net/
registry=http://dev-npm.k8s.com.cn/
strict-peer-dependencies=false
always-auth=true
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM 172.22.96.34/front-end/component-store:base-0.1 as builder
FROM kubebb/component-store-base:main as builder
LABEL maintainer="zhangpc<zhang.pengcheng3@neolink.com>"

ENV NODE_ENV production
Expand All @@ -11,7 +11,7 @@ WORKDIR /usr/src/app
# package files
RUN nr build

FROM 172.22.96.34/front-end/component-store:base-0.1-prod
FROM kubebb/component-store-base-pro:main

COPY --from=builder /usr/src/app/packages/bff-server/configs ./configs
COPY --from=builder /usr/src/app/packages/bff-server/dist ./dist
Expand Down
5 changes: 1 addition & 4 deletions base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@ ADD packages/shared-components /usr/src/app/packages/shared-components
COPY packages/bff-server/package.json /usr/src/app/packages/bff-server
COPY packages/portal/package.json /usr/src/app/packages/portal

ARG _authToken

RUN npm set //dev-npm.tenxcloud.net/:_authToken="${_authToken}" \
&& npm i pnpm @antfu/ni -g \
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm i pnpm @antfu/ni -g \
&& ni
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

image="172.22.96.34/kubebb/component-store:latest"
image="kubebb/component-store:latest"

# 1.构建基础镜像
./update_base_image.sh $1
Expand Down
2 changes: 1 addition & 1 deletion packages/bff-server/.npmrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
registry=http://dev-npm.tenxcloud.net/
registry=http://dev-npm.k8s.com.cn/
always-auth=true
strict-peer-dependencies=false
2 changes: 1 addition & 1 deletion packages/portal/src/utils/__utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getAuthorization = utils.getAuthorization;
/** 获取 axios 默认配置,也可在配置中指定拦截器,用于数据源初始化 axios handler */
utils.getAxiosHanlderConfig = function __getAxiosHanlderConfig() {
return () => ({
// 详细配置见:http://dev-npm.tenxcloud.net/-/web/detail/@yunti/lowcode-datasource-axios-handler
// 详细配置见:http://dev-npm.k8s.com.cn/-/web/detail/@yunti/lowcode-datasource-axios-handler
interceptors: {
request: [
{
Expand Down
5 changes: 1 addition & 4 deletions pro.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@ COPY pnpm-workspace.yaml /usr/src/app/
COPY .npmrc /usr/src/app/
COPY packages/bff-server/package.json /usr/src/app/packages/bff-server

ARG _authToken

RUN npm set //dev-npm.tenxcloud.net/:_authToken="${_authToken}" \
&& npm i pnpm @antfu/ni -g \
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm i pnpm @antfu/ni -g \
&& ni --ignore-scripts
8 changes: 4 additions & 4 deletions update_base_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
set -e

# build base image
base_image="172.22.96.34/front-end/component-store:base-0.1"
docker build --build-arg _authToken=$1 -t ${base_image} -f base.dockerfile .
base_image="kubebb/component-store-base:main"
docker build --build-arg -t ${base_image} -f base.dockerfile .
docker push ${base_image}

# build prod base image
base_image_prod="172.22.96.34/front-end/component-store:base-0.1-prod"
docker build --build-arg _authToken=$1 -t ${base_image_prod} -f pro.dockerfile .
base_image_prod="kubebb/component-store-base-pro:main"
docker build --build-arg -t ${base_image_prod} -f pro.dockerfile .
docker push ${base_image_prod}

0 comments on commit 3e43eaa

Please sign in to comment.