|
| 1 | +name: Build Docker image |
| 2 | + |
| 3 | +on: [ push, pull_request ] |
| 4 | + |
| 5 | +jobs: |
| 6 | + prepare: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + outputs: |
| 9 | + FULL_IMAGE_TAG: ${{ steps.tag.outputs.tag }} |
| 10 | + steps: |
| 11 | + - name: Set Tag |
| 12 | + id: tag |
| 13 | + run: | |
| 14 | + export CI_COMMIT_SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-8) |
| 15 | + echo $CI_COMMIT_SHORT_SHA; |
| 16 | + echo ${GITHUB_REF##*/}; |
| 17 | + echo $version_pattern; |
| 18 | + if [[ ${GITHUB_REF} =~ $version_pattern ]]; then |
| 19 | + echo "::set-output name=tag::${GITHUB_REF##*/}" |
| 20 | + elif [ ${GITHUB_REF##*/} = "main" ]; then |
| 21 | + echo "::set-output name=tag::stg-$CI_COMMIT_SHORT_SHA" |
| 22 | + else |
| 23 | + echo "::set-output name=tag::$CI_COMMIT_SHORT_SHA" |
| 24 | + fi |
| 25 | + env: |
| 26 | + version_pattern: "tags\\/v[0-9]+\\.[0-9]+\\.[0-9]+" |
| 27 | + |
| 28 | + |
| 29 | + build-image: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + needs: prepare |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Echo tag |
| 35 | + id: echotag |
| 36 | + env: |
| 37 | + IMAGE_TAG: ${{ needs.prepare.outputs.FULL_IMAGE_TAG }} |
| 38 | + run: | |
| 39 | + echo "Building an image with the following tag:" |
| 40 | + echo $IMAGE_TAG |
| 41 | + - name: Checkout |
| 42 | + uses: actions/checkout@v2 |
| 43 | + |
| 44 | +# - name: Configure AWS Credentials |
| 45 | +# uses: aws-actions/configure-aws-credentials@v1 |
| 46 | +# id: configure-aws-creds |
| 47 | +# env: |
| 48 | +# AWS_REGION: us-west-2 |
| 49 | +# with: |
| 50 | +# aws-access-key-id: ${{ secrets.ECR_AWS_ACCESS_KEY_ID }} |
| 51 | +# aws-secret-access-key: ${{ secrets.ECR_AWS_SECRET_ACCESS_KEY }} |
| 52 | +# aws-region: ${{ env.AWS_REGION }} |
| 53 | +# |
| 54 | +# - name: Login to Amazon ECR |
| 55 | +# id: login-ecr |
| 56 | +# uses: aws-actions/amazon-ecr-login@v1 |
| 57 | +# |
| 58 | +# - name: Build and push to ECR |
| 59 | +# id: build-push |
| 60 | +# env: |
| 61 | +# ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} |
| 62 | +# ECR_REPOSITORY: jira-bugzilla-integration |
| 63 | +# IMAGE_TAG: ${{ needs.prepare.outputs.FULL_IMAGE_TAG }} |
| 64 | +# run: | |
| 65 | +# printf '{\n "commit": "%s",\n "version": "%s",\n "image_tag": "%s",\n "source": "%s",\n "build": "%s"\n}\n' \ |
| 66 | +# "$GITHUB_SHA" \ |
| 67 | +# "$GITHUB_REF" \ |
| 68 | +# "$IMAGE_TAG" \ |
| 69 | +# "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY" \ |
| 70 | +# "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" > ./version.json |
| 71 | +# docker build --file infra/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . |
| 72 | +# docker image tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 73 | +# docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
| 74 | +# docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest |
| 75 | +# - name: Logut of Amazon ECR |
| 76 | +# if: always() |
| 77 | +# run: | |
| 78 | +# docker logout ${{ steps.login-ecr.outputs.registry }} |
0 commit comments