|
| 1 | +name: Create and publish a Docker image |
| 2 | + |
| 3 | +# Configure this workflow to run every time a change is pushed to a branch |
| 4 | +# whose name starts with `release/` or any time a tag is created; this workflow |
| 5 | +# is also run any time a GitHub release is created or updated ("unpublish" and |
| 6 | +# deletions do not cause it to run). |
| 7 | +on: |
| 8 | + push: |
| 9 | + branches: ['release/**'] |
| 10 | + tags: ['*'] |
| 11 | + release: |
| 12 | + types: [created, edited, prereleased, published, released] |
| 13 | + |
| 14 | +# Set up the container image specification to be `quay.io/pbench/file-relay`. |
| 15 | +env: |
| 16 | + REGISTRY: quay.io |
| 17 | + ORGANIZATION: pbench |
| 18 | + IMAGE_NAME: file-relay |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-and-push-image: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + # Set the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 25 | + permissions: |
| 26 | + contents: read |
| 27 | + packages: write |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v3 |
| 32 | + |
| 33 | + - name: Log in to the Container registry |
| 34 | + uses: docker/login-action@v2 |
| 35 | + with: |
| 36 | + registry: ${{ env.REGISTRY }} |
| 37 | + username: ${{ secrets.REGISTRY_USERNAME }} |
| 38 | + password: ${{ secrets.REGISTRY_ROBOT_TOKEN }} |
| 39 | + |
| 40 | + # Extract metadata from the Git reference and the GitHub event. |
| 41 | + # Subsequent steps can reference the values via `steps.meta.outputs.<key>`. |
| 42 | + # The `images` value provides the name for the container image which is |
| 43 | + # used in tags and labels. |
| 44 | + - name: Extract metadata (tags, labels) from Git for Docker |
| 45 | + id: meta |
| 46 | + uses: docker/metadata-action@v4 |
| 47 | + with: |
| 48 | + images: ${{ env.REGISTRY }}/${{ env.ORGANIZATION }}/${{ env.IMAGE_NAME }} |
| 49 | + |
| 50 | + # Build the container image based on the Dockerfile and the rest of the |
| 51 | + # files found in the root of the Git checkout. If the build succeeds, |
| 52 | + # the image is pushed to the registry indicated by the tags. |
| 53 | + - name: Build and push Docker image |
| 54 | + uses: docker/build-push-action@v4 |
| 55 | + with: |
| 56 | + context: . |
| 57 | + file: Dockerfile |
| 58 | + network: host |
| 59 | + push: true |
| 60 | + tags: ${{ steps.meta.outputs.tags }} |
| 61 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments