Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add auto image build script when there is new pull request #2

Merged
merged 1 commit into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/image_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Build image

on:
push:
branches: [main]
env:
REGISTRY: docker.io
IMAGE_NAME: yuntijs/gql-sdk-generator
DOCKER_USER: yuntijs

jobs:
image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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.0.1 as default"
TAG=v0.0.1
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/[email protected]
name: Get short commit sha
id: short-sha
- name: setting token to npmrc
run: |
echo '//dev-npm.tenxcloud.net/:_authToken="${{ secrets.NPMTOKEN }}"' > /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 }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:v${{ steps.set-env.outputs.DATE }}-${{ steps.short-sha.outputs.sha }}
${{ 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"
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=linux/amd64 node:18.16-alpine as builder
FROM node:18.16-alpine as builder

ARG sdk_package_name
ARG sdk_yunti_name
Expand All @@ -13,11 +13,8 @@ WORKDIR /tmp/bff-sdk-template

COPY . /tmp/bff-sdk-template/

ARG _authToken

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

RUN chmod +x ./publish.sh
ENTRYPOINT ["sh", "publish.sh"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# bff-sdk-template

template for bff sdk

```bash
# you should npm login first or run `npm set` command first, like: npm set //dev-npm.tenxcloud.net/:_authToken=xxxxx
docker build -t kubebb/gql-sdk-generator:latest -f Dockerfile --secret id=npmrc,src=$HOME/.npmrc .
```