Skip to content

Commit f03bc31

Browse files
committed
feat: add auto image build script when there is new pull request
Signed-off-by: Abirdcfly <[email protected]>
1 parent 75e7914 commit f03bc31

File tree

3 files changed

+82
-6
lines changed

3 files changed

+82
-6
lines changed

.github/workflows/image_build.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Build image
2+
3+
on:
4+
push:
5+
branches: [main]
6+
env:
7+
REGISTRY: docker.io
8+
IMAGE_NAME: yuntijs/gql-sdk-generator
9+
DOCKER_USER: yuntijs
10+
11+
jobs:
12+
image:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
- name: Set Variable
19+
id: set-env
20+
run: |
21+
TAG=$(git describe --tags --abbrev=0 --match 'v*' 2> /dev/null) || true
22+
if [ -z "$TAG" ]; then
23+
echo "No tag found, use v0.0.1 as default"
24+
TAG=v0.0.1
25+
fi
26+
echo "TAG=${TAG}" >> $GITHUB_OUTPUT
27+
echo "DATE=$(TZ=Asia/Shanghai date +'%Y%m%d')" >> $GITHUB_OUTPUT
28+
- name: Show Variable
29+
run: echo "varibables ${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}"
30+
- name: Extract metadata (tags, labels) for Docker
31+
id: meta
32+
uses: docker/metadata-action@v5
33+
with:
34+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v3
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@v3
39+
with:
40+
buildkitd-flags: --debug
41+
config-inline: |
42+
[worker.oci]
43+
max-parallelism = 1
44+
- name: Login to the dockerhub Registry
45+
uses: docker/login-action@v3
46+
with:
47+
username: ${{ env.DOCKER_USER }}
48+
password: ${{ secrets.DOCKER_TOKEN }}
49+
- uses: benjlevesque/[email protected]
50+
name: Get short commit sha
51+
id: short-sha
52+
- name: setting token to npmrc
53+
run: |
54+
echo '//dev-npm.tenxcloud.net/:_authToken="${{ secrets.NPMTOKEN }}"' > /tmp/npmrc
55+
- name: Build and push
56+
id: push
57+
uses: docker/build-push-action@v5
58+
with:
59+
context: .
60+
file: Dockerfile
61+
platforms: linux/amd64,linux/arm64
62+
tags: |
63+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
64+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }}
65+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }}
66+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.set-env.outputs.TAG }}-${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }}
67+
${{ steps.meta.outputs.tags }}
68+
push: true
69+
build-args: |
70+
BUILD_ID=${{ env.SEMREV_LABEL }}
71+
BUILD_DATE=${{ env.BUILD_DATE }}
72+
secret-files: |
73+
"npmrc=/tmp/npmrc"

Dockerfile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM --platform=linux/amd64 node:18.16-alpine as builder
1+
FROM node:18.16-alpine as builder
22

33
ARG sdk_package_name
44
ARG sdk_yunti_name
@@ -13,11 +13,8 @@ WORKDIR /tmp/bff-sdk-template
1313

1414
COPY . /tmp/bff-sdk-template/
1515

16-
ARG _authToken
17-
18-
RUN npm set //dev-npm.tenxcloud.net/:_authToken="${_authToken}" \
19-
&& npm i pnpm @antfu/ni zx -g \
20-
&& ni --ignore-scripts
16+
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm i pnpm @antfu/ni zx -g
17+
RUN --mount=type=secret,id=npmrc,target=/root/.npmrc ni --ignore-scripts --registry=http://dev-npm.tenxcloud.net
2118

2219
RUN chmod +x ./publish.sh
2320
ENTRYPOINT ["sh", "publish.sh"]

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# bff-sdk-template
2+
23
template for bff sdk
4+
5+
```bash
6+
# you should npm login first or run `npm set` command first, like: npm set //dev-npm.tenxcloud.net/:_authToken=xxxxx
7+
docker build -t kubebb/gql-sdk-generator:latest -f Dockerfile --secret id=npmrc,src=$HOME/.npmrc .
8+
```

0 commit comments

Comments
 (0)