This commit is contained in:
jagger 2024-11-08 16:14:32 +08:00
parent 7b5f952d9f
commit 073bbd233c
1 changed files with 18 additions and 9 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 }}