From 6ba1be6bacf24bf0f8f4640f43d8cc5a98a8502f Mon Sep 17 00:00:00 2001 From: gaotianyu Date: Thu, 26 Sep 2024 15:08:20 +0800 Subject: [PATCH] CI: add build image workflow --- .github/ISSUE_TEMPLATE/bug_report.md | 38 +++++++++++++++++ .github/ISSUE_TEMPLATE/feature_request.md | 20 +++++++++ .github/workflows/build-image.yml | 51 +++++++++++++++++++++++ Makefile | 12 +++--- 4 files changed, 115 insertions(+), 6 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/build-image.yml diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..272cbd7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,38 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..24473de --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml new file mode 100644 index 0000000..fc944f8 --- /dev/null +++ b/.github/workflows/build-image.yml @@ -0,0 +1,51 @@ +name: Build and Push Docker Image + +on: + push: + branches: + - main + - 'release/*' + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up docker buildx + id: buildx + uses: docker/setup-buildx-action@v2 + with: + version: latest + + - name: Docker login + env: + DOCKER_USERNAME: ${{ secrets.ALIYUN_REGISTRY_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.ALIYUN_REGISTRY_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin registry.cn-shanghai.aliyuncs.com + + - name: Extract branch name + id: extract_branch + run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + + - name: Extract Tag + id: extract_tag + run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//} + + - name: Run buildx + run: | + tag=latest + if [[ "${{ steps.extract_branch.outputs.branch }}" == "main" ]];then + tag=latest + elif [[ "${{ steps.extract_tag.outputs.version }}" == v* ]]; then + tag="${{ steps.extract_tag.outputs.version }}" + fi + + echo extract_tag ${{ steps.extract_tag.outputs.version }} + echo extract_branch ${{ steps.extract_branch.outputs.branch }} + echo current tag is ${tag} + + docker buildx build --platform linux/amd64,linux/arm64 --push -f deploy/docker/Dockerfile -t registry.cn-shanghai.aliyuncs.com/openhydra/aes-ai-tutor:${tag} . \ No newline at end of file diff --git a/Makefile b/Makefile index a2dae01..cf41a76 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ -REGISTRY ?= hub.sh.99cloud.net +REGISTRY ?= registry.cn-shanghai.aliyuncs.com/openhydra IMAGETAG ?= $(shell git rev-parse --abbrev-ref HEAD)-$(shell git rev-parse --verify HEAD)-$(shell date -u '+%Y%m%d%I%M%S') BRANCH ?= $(shell git branch --show-current) .PHONY: image image: - docker build -t $(REGISTRY)/aes/aes-ai-tutor:$(IMAGETAG) -f deploy/docker/Dockerfile . --load + docker build -t $(REGISTRY)/aes-ai-tutor:$(IMAGETAG) -f deploy/docker/Dockerfile . --load .PHONY: image-then-push image-then-push: - docker build -t $(REGISTRY)/aes/aes-ai-tutor:$(IMAGETAG) -f deploy/docker/Dockerfile . --load - docker tag $(REGISTRY)/aes/aes-ai-tutor:$(IMAGETAG) $(REGISTRY)/aes/aes-ai-tutor:$(BRANCH) - docker push $(REGISTRY)/aes/aes-ai-tutor:$(IMAGETAG) - docker push $(REGISTRY)/aes/aes-ai-tutor:$(BRANCH) \ No newline at end of file + docker build -t $(REGISTRY)/aes-ai-tutor:$(IMAGETAG) -f deploy/docker/Dockerfile . --load + docker tag $(REGISTRY)/aes-ai-tutor:$(IMAGETAG) $(REGISTRY)/aes/aes-ai-tutor:$(BRANCH) + docker push $(REGISTRY)/aes-ai-tutor:$(IMAGETAG) + docker push $(REGISTRY)/aes-ai-tutor:$(BRANCH) \ No newline at end of file