fix ci/cd bug

This commit is contained in:
jagger 2024-11-05 16:54:29 +08:00
parent e843c4d359
commit b3b63c2089
2 changed files with 19 additions and 10 deletions

View File

@ -38,17 +38,26 @@ jobs:
username: ${{ secrets.ALIYUN_USERNAME }}
password: ${{ secrets.ALIYUN_PASSWORD }}
- name: Get commit ID and build time
id: get_tags
run: |
echo "::set-output name=build_time::$(date +'%Y%m%d%H%M%S')"
- name: Build and push multi-arch image
run: |
docker buildx build --platform linux/amd64,linux/arm64 -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} --push .
docker buildx build \
--platform linux/amd64,linux/arm64 \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
-t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.get_tags.outputs.build_time }} \
--push .
- name: Set up SSH key
- name: Set up Kubernetes CLI
uses: azure/setup-kubectl@v1
- name: Configure kubeconfig
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG }}" > ~/.kube/config
- name: SSH to remote server and restart deployment
if: github.event_name != 'pull_request'
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "kubectl rollout restart deployment ${{ secrets.SSH_DEPLOYMENT }} -n ${{ secrets.SSH_NAMESPACE }}"
- name: Restart Deployment
run: kubectl rollout restart deployment ${{ secrets.SSH_DEPLOYMENT }}ts.SSH_HOST }} "kubectl rollout restart deployment ${{ secrets.SSH_DEPLOYMENT }} -n ${{ secrets.SSH_NAMESPACE }}"

View File

@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.22.4-alpine3.20 AS builder
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
WORKDIR /app
COPY . .