From 7dc755d257207f9149658e62bc103937626156e2 Mon Sep 17 00:00:00 2001 From: xiehaijun Date: Sat, 26 Jul 2025 18:15:49 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E8=87=AA=E5=8A=A8cicd=E6=93=8D=E4=BD=9C.txt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 其他自动cicd操作.txt | 147 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 其他自动cicd操作.txt diff --git a/其他自动cicd操作.txt b/其他自动cicd操作.txt new file mode 100644 index 0000000..ceaebc8 --- /dev/null +++ b/其他自动cicd操作.txt @@ -0,0 +1,147 @@ +name: demo pipeline + +on: + push: + branches: [ "main" ] + +jobs: + build: + runs-on: [ubuntu-latest] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + - name: Build with Maven + run: mvn clean install -DskipTests + - name: Login to docker hub + run: docker login -u "${{ secrets.DOCKER_USERNAME }}" -p "${{ secrets.DOCKER_PASSWORD }}" + - name: Build docker image + run: docker build -t . + - name: Push docker image + run: docker push :latest + + deploy: + needs: build + runs-on: [] + steps: + - name: Check Docker Installation + run: | + if ! [ -x "$(command -v docker)" ]; then + echo "Error: Docker is not installed." >&2 + exit 1 + fi + - name: Pull image from docker hub + run: sudo docker pull :latest + - name: Delete existing container + run: | + if [ "$(sudo docker ps -aq -f name=demo)" ]; then + sudo docker rm -f demo + fi + - name: Run docker container + run: sudo docker run -d -p 8080:8080 --name demo + + + +ssh连接:https://www.freebuf.com/articles/sectool/435623.html 和 https://github.com/appleboy/ssh-action/blob/master/README.zh-cn.md 以及 https://blog.gitcode.com/6676e2ca182e0fcb7d332c92dd2968c7.html + - name: Deploy blog.emooa.com + run: | + mkdir -p ~/.ssh + echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + echo "Removing /var/www/$USER_NAME/blog" + ssh $USER_NAME@$IP "rm -f /var/www/$USER_NAME/blog || echo 'no such directory.'" + + echo "Creating /var/www/$USER_NAME/blog" + ssh $USER_NAME@$IP "mkdir -p /var/www/$USER_NAME/blog" + + echo "Copying 'public' directory to /var/www/$USER_NAME/blog" + scp -r public/* $USER_NAME@$IP:/var/www/$USER_NAME/blog/ + + +发布 https://github.com/marketplace/actions/upload-files-to-a-github-release +steps: + - name: Upload files to a GitHub release + uses: svenstaro/upload-release-action@2.9.0 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: path/to/your/asset.zip # The file to attach to the release + tag: ${{ github.ref }} # The tag associated with the release + +steps: + - uses: actions/checkout@v4 # Checkout your repository code + - name: Build something + run: | + # Your build commands that generate the files you want to attach + echo "This is a test artifact." > my-artifact.txt + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: my-build-output # Name of the artifact + path: my-artifact.txt # Path to the file or directory to upload + +name: Node.js CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Use Node.js 18.x + uses: actions/setup-node@v4 + with: + node-version: 18.x + cache: 'npm' + - run: npm install + - run: npm run build --if-present + - name: Upload a Build Artifact + uses: actions/upload-artifact@v4 + with: + name: dist + path: dist/ + release: + needs: build + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v4 + - name: Download Build Artifact + uses: actions/download-artifact@v4 + with: + name: dist + path: dist/ + - name: Create Release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + body: | + 自动发布的版本 + draft: false + prerelease: false + - name: Upload Release Asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./dist/your-executable + asset_name: your-executable + asset_content_type: application/octet-stream + + +k8s操作 +https://spacelift.io/blog/github-actions-kubernetes#why-use-github-actions-for-kubernetes-deployments +https://github.com/actions-hub/kubectl \ No newline at end of file