diff --git a/.gitea/workflows/docker.yaml b/.gitea/workflows/docker.yaml index aa62c8e..9a7fc7f 100644 --- a/.gitea/workflows/docker.yaml +++ b/.gitea/workflows/docker.yaml @@ -31,50 +31,70 @@ jobs: runs-on: ubuntu-latest strategy: matrix: + # 使用gitea-tool-cache需要指定具体的版本号 go: ["1.24.5"] steps: - name: Checkout uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/checkout@v4 + # 将.env环境变量配置文件拷贝致gitea runner容器 + - name: copy env file to runner container + uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/ssh-action@v0.1.10 + with: + host: ${{ env.SSH_HOST }} + username: ${{ env.SSH_USER }} + password: ${{ env.SSH_PASSWORD }} + port: ${{ env.SSH_PORT }} + debug: true + script: | + mkdir -p /install/cicd_env_files + cd /install/cicd_env_files + docker cp ${{env.JOB_CONTAINER_NAME}}:${{gitea.WORKSPACE}}/deploy/.env ./.env + source ./.env + docker cp ${{env.JOB_CONTAINER_NAME}}:${{gitea.WORKSPACE}}/docs/${SERVICE_NAME}.json . + docker cp .env ${{ vars.RUNNER_CONTAINER_NAME }}:/.env + docker exec ${{ vars.RUNNER_CONTAINER_NAME }} /bin/bash -c "source /.env" + - name: Install Go environment - uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/setup-go@v4 + uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/gitea-tool-cache@v5 + with: + # 需要指定具体版本号! + go-version: ${{ matrix.go }} + + - uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/setup-go@v2 with: go-version: ${{ matrix.go }} + - uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/cache@v3 + with: + path: | + ~/.cache/go-build + ~/go/pkg/mod + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + - name: Prepare GO environment run: | - go env -w GOPROXY=https://goproxy.cn,direct + go env -w GOPROXY=https://goproxy.cn,direct go env -w GOPRIVATE="${{ vars.DOMAIN_OF_GITEA}}" - git config --global url."https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/".insteadOf "https://${{ vars.DOMAIN_OF_GITEA}}/" + git config --global url."https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/".insteadOf "https://${{ vars.DOMAIN_OF_GITEA}}/" - - name: Debug filesystem and build docker image + - name: Build and push docker image run: | - echo "=== Debug Information ===" - echo "Current working directory: $(pwd)" - echo "Gitea workspace: ${{ gitea.workspace }}" - echo "Listing current directory:" - ls -la - echo "Checking if deploy directory exists:" - ls -la deploy/ || echo "deploy directory not found" - echo "Checking if .env file exists:" - ls -la deploy/.env || echo ".env file not found in deploy/" - echo "Trying to find .env files:" - find . -name ".env" -type f 2>/dev/null || echo "No .env files found" - echo "=========================" - - # Try to source the .env file with proper path - if [ -f "./deploy/.env" ]; then - echo "Found .env file, sourcing it..." - source ./deploy/.env - else - echo "ERROR: .env file not found at ./deploy/.env" - exit 1 - fi - + source ${{gitea.WORKSPACE}}/deploy/.env go clean -modcache go mod tidy make build-linux make docker make publish-docker - make docker-run \ No newline at end of file + make docker-run + + - name: Build APIDOC docker image + run: | + source ${{gitea.WORKSPACE}}/deploy/.env + echo ${SERVICE_NAME} + echo ${APIDOC_CONTAINER_NAME} + echo ${SWAGGER_JSON} + make swagger-docker \ No newline at end of file