ci(docker): 简化并优化docker构建工作流

移除不必要的环境文件拷贝步骤,更新Go安装方式
添加调试信息以帮助定位.env文件问题
This commit is contained in:
邹方成 2025-10-16 14:20:28 +08:00
parent 9db33e7db1
commit ae8e924045

View File

@ -31,70 +31,50 @@ 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/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
uses: https://${{ env.GIT_USERNAME }}:${{ env.GIT_PASSWORD }}@${{ vars.DOMAIN_OF_GITEA}}/actions/setup-go@v4
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: Build and push docker image
- name: Debug filesystem and build docker image
run: |
source ${{gitea.WORKSPACE}}/deploy/.env
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
go clean -modcache
go mod tidy
make build-linux
make docker
make publish-docker
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
make docker-run