|
| 1 | +name: Build and Push OCI Image |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + tags: |
| 8 | + - 'v*.*.*' |
| 9 | + # can only be executed by people with write access on repository |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +jobs: |
| 13 | + prepare: |
| 14 | + name: Determine image tag |
| 15 | + runs-on: ubuntu-latest |
| 16 | + # Prevent execution on forks |
| 17 | + if: github.repository_owner == 'iExecBlockchainComputing' |
| 18 | + outputs: |
| 19 | + image_tag: ${{ steps.determine-tag.outputs.image_tag }} |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@v6 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Determine Docker tag based on Git ref |
| 27 | + id: determine-tag |
| 28 | + run: | |
| 29 | + if [ "${{ github.ref_type }}" = "tag" ] ; then |
| 30 | + # Since this workflow only triggers on tags matching 'v*.*.*' we know we're always dealing with a version tag |
| 31 | + TAG_ON_MAIN=$(git branch -r --contains ${{ github.sha }} 'origin/main') |
| 32 | +
|
| 33 | + if [ -z "$TAG_ON_MAIN" ] ; then |
| 34 | + echo "Error: Tag ${{ github.ref_name }} is not on main branch" |
| 35 | + echo "Tags must be created on main branch to generate X.Y.Z image tags" |
| 36 | + exit 1 |
| 37 | + fi |
| 38 | +
|
| 39 | + GITHUB_REF_NAME="${{ github.ref_name }}" |
| 40 | + echo "Processing tag on main branch: ${{ github.ref_name }}" |
| 41 | + echo "image_tag=${GITHUB_REF_NAME#v}" | tee -a $GITHUB_OUTPUT |
| 42 | + else |
| 43 | + if [ "${{ github.event_name }}" = "pull_request" ] ; then |
| 44 | + SHORT_SHA=$(echo ${{ github.event.pull_request.head.sha }} | cut -c1-8) |
| 45 | + else |
| 46 | + SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8) |
| 47 | + fi |
| 48 | +
|
| 49 | + if [ "${{ github.ref_name }}" = "main" ] ; then |
| 50 | + echo "Processing main branch" |
| 51 | + echo "image_tag=dev-${SHORT_SHA}" | tee -a $GITHUB_OUTPUT |
| 52 | + else |
| 53 | + # This covers other branches |
| 54 | + echo "Processing feat/fix branch ${{ github.head_ref }}" |
| 55 | + echo "image_tag=feature-${SHORT_SHA}" | tee -a $GITHUB_OUTPUT |
| 56 | + fi |
| 57 | + fi |
| 58 | +
|
| 59 | + build-oci-image: |
| 60 | + name: Build OCI image |
| 61 | + needs: prepare |
| 62 | + uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/docker-build.yml@docker-build-v3.3.0 |
| 63 | + with: |
| 64 | + image-name: docker-regis.iex.ec/offchain-python-hello-world |
| 65 | + image-tag: ${{ needs.prepare.outputs.image_tag }} |
| 66 | + dockerfile: offchain-computing/Dockerfile |
| 67 | + context: offchain-computing |
| 68 | + registry: docker-regis.iex.ec |
| 69 | + push: true |
| 70 | + security-scan: true |
| 71 | + security-report: "comment" |
| 72 | + hadolint: true |
| 73 | + platform: linux/amd64 |
| 74 | + secrets: |
| 75 | + dockerhub-username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 76 | + dockerhub-password: ${{ secrets.DOCKERHUB_TOKEN_PULL_ONLY }} |
| 77 | + username: ${{ secrets.NEXUS_USERNAME }} |
| 78 | + password: ${{ secrets.NEXUS_PASSWORD }} |
0 commit comments