最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

amazon web services - Docker build from github actions that pulls from another repo - Stack Overflow

programmeradmin0浏览0评论

I have a poetry project that pulls in another repo. It works fine locally and from my lint github action, but when building a docker container from the GHA it fails. I can also build the docker container locally. Since the lint action works I know my SSH key and AWS permissions are all good.

Here is the build yaml:

  build:
    needs: lint
    runs-on: ubuntu-latest

    permissions:
      id-token: write
      contents: read

    env:
      DOCKER_BUILD_FILE: "Dockerfile"
      DOCKER_BUILD_DIR: "."
      IMAGE_TAG: latest

    outputs:
      image_tag: ${{ steps.build-publish.outputs.image_tag }}
      full_image: ${{ steps.build-publish.outputs.full_image }}

    steps:
      - name: Set TARGET environment variables
        run: |
          TARGET_ENV="${{ github.ref_name }}"
          if [[ "$TARGET_ENV" == "main" ]]; then
            TARGET_ENV=test
          fi
          TARGET_ENV=$(echo "$TARGET_ENV" | tr '[:upper:]' '[:lower:]')
          echo "TARGET_ENV=$TARGET_ENV" >> $GITHUB_ENV

          TARGET_NAME="${{ github.event.repository.name }}-$TARGET_ENV"
          TARGET_NAME=$(echo "$TARGET_NAME" | tr '[:upper:]' '[:lower:]')
          echo "TARGET_NAME=$TARGET_NAME" >> $GITHUB_ENV

      - name: Check out the code
        uses: actions/checkout@v4

      - name: Set up SSH agent
        uses: webfactory/[email protected]
        with:
          ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
          debug-mode: true

      - name: Configure Git to use SSH
        run: |
          git config --global url."ssh://[email protected]/".insteadOf "/"

      - name: Add GitHub to known hosts
        run: |
          mkdir -p ~/.ssh
          ssh-keyscan github >> ~/.ssh/known_hosts

      - name: Configure AWS Credentials
        id: aws-creds
        uses: aws-actions/configure-aws-credentials@v4
        with:
          aws-region: ${{ vars.ACTIONS_AWS_REGION }}
          role-to-assume: arn:aws:iam::${{ vars.ACTIONS_AWS_ACCOUNT }}:role/${{ vars.ACTIONS_IAM_ROLE }}
          role-session-name: build-${{ env.TARGET_NAME }}

      - name: Login to Amazon ECR
        id: login-ecr
        uses: aws-actions/amazon-ecr-login@v2
        with:
          registries: ${{ vars.ACTIONS_AWS_ACCOUNT }}
          mask-password: "true"

      - name: Build, tag, and push image to Amazon ECR
        id: build-publish
        shell: bash
        env:
          ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
          ECR_REPOSITORY: ${{ env.TARGET_NAME }}
          INCLUDE_DB: "false"
        run: |
          docker build --ssh default --build-arg="INCLUDE_DB=${INCLUDE_DB}" "${DOCKER_BUILD_DIR}" -f "${DOCKER_BUILD_FILE}" -t "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
            docker push "$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"

          echo "IMAGE $IMAGE_TAG is pushed to $ECR_REGISTRY/$ECR_REPOSITORY"

          echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
          echo "full_image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

It fails with:

HangupException
The remote server unexpectedly closed the connection.

When it runs this from poetry:

other_repo = { git = "ssh://[email protected]/my_company/other_repo.git" }

Any ideas on what the issue is or how I can debug this?

发布评论

评论列表(0)

  1. 暂无评论