测试调用调用执行 #10
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy CI/CD By Example | |
on: | |
push: | |
branches: | |
- main | |
- feature/before_after_func | |
# pull_request: | |
# branches: | |
# - main | |
env: | |
DOCKER_USERNAME: ${{ vars.DOCKER_USERNAME }} | |
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} | |
DOCKER_REGISTRY_URL: "registry.cn-hangzhou.aliyuncs.com" # 示例:阿里云私有镜像仓库 | |
DOCKER_IMAGE: "registry.cn-hangzhou.aliyuncs.com/example-namespace/example-deployments" | |
DOCKER_IMAGE_TAG: "" | |
CONTAINER_NAME: "example-deployments" | |
DOCKER_RUN_PARAMS: "-p 88:80 -e APP_ENV=example" | |
SERVER_HOST: ${{ vars.SERVER_HOST }} | |
SERVER_USER: ${{ vars.SERVER_USER }} | |
SERVER_SSH_PRIVATE_KEY: ${{ secrets.SERVER_SSH_PRIVATE_KEY }} | |
jobs: | |
CI-Build: | |
runs-on: ubuntu-latest | |
environment: testing # 指定环境 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Cache Docker layers | |
uses: actions/cache@v3 | |
with: | |
path: /tmp/.buildx-cache | |
key: ${{ runner.os }}-buildx-${{ github.sha }} | |
restore-keys: | | |
${{ runner.os }}-buildx- | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.DOCKER_USERNAME }} | |
password: ${{ env.DOCKER_PASSWORD }} | |
registry: ${{ env.DOCKER_REGISTRY_URL }} # 私有镜像仓库,需要配置此地址 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: ./tests/Dockerfile | |
push: true | |
tags: ${{ env.DOCKER_IMAGE }}:latest | |
CD-Deploy: | |
needs: CI-Build | |
runs-on: ubuntu-latest | |
environment: testing | |
steps: | |
- name: Deploy to server | |
run: | | |
export BEFORE_FUNC=$(cat <<'EOF' | |
echo "I am before function" | |
sudo touch /data/aaa.txt | |
EOF | |
) | |
export AFTER_FUNC=$(cat <<'EOF' | |
echo "I am after function" | |
sudo touch /data/aaa_bbb.txt | |
EOF | |
) | |
# 部署 | |
deploy_docker_url="https://raw.githubusercontent.com/jefferyjob/deployments/refs/heads/${{ github.ref_name }}/scripts/deploy.docker.sh" | |
echo "deploy_docker_url: $deploy_docker_url" | |
curl -o deploy.sh $deploy_docker_url | |
chmod +x deploy.sh | |
./deploy.sh key deploy | |