|
15 | 15 | permissions: |
16 | 16 | contents: read # to fetch code (actions/checkout) |
17 | 17 |
|
| 18 | + |
| 19 | +env: |
| 20 | + # Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action) |
| 21 | + # For a new commit on default branch (main), use the literal tag 'latest' on Docker image. |
| 22 | + # For a new commit on other branches, use the branch name as the tag for Docker image. |
| 23 | + # For a new tag, copy that tag name as the tag for Docker image. |
| 24 | + IMAGE_TAGS: | |
| 25 | + type=raw,value=latest,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} |
| 26 | + type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} |
| 27 | + type=ref,event=tag |
| 28 | + # Define default tag "flavor" for docker/metadata-action per |
| 29 | + # https://github.com/docker/metadata-action#flavor-input |
| 30 | + # We manage the 'latest' tag ourselves to the 'main' branch (see settings above) |
| 31 | + TAGS_FLAVOR: | |
| 32 | + latest=false |
| 33 | + # Architectures / Platforms for which we will build Docker images |
| 34 | + # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work. |
| 35 | + # If this is NOT a PR (e.g. a tag or merge commit), also build for ARM64. |
| 36 | + PLATFORMS: linux/amd64${{ github.event_name != 'pull_request' && ', linux/arm64' || '' }} |
| 37 | + |
| 38 | + |
18 | 39 | jobs: |
19 | | - docker: |
| 40 | + ############################################### |
| 41 | + # Build/Push the 'dspace/dspace-angular' image |
| 42 | + ############################################### |
| 43 | + dspace-angular: |
20 | 44 | # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' |
21 | 45 | if: github.repository == 'dspace/dspace-angular' |
22 | 46 | runs-on: ubuntu-latest |
23 | | - env: |
24 | | - # Define tags to use for Docker images based on Git tags/branches (for docker/metadata-action) |
25 | | - # For a new commit on default branch (main), use the literal tag 'dspace-7_x' on Docker image. |
26 | | - # For a new commit on other branches, use the branch name as the tag for Docker image. |
27 | | - # For a new tag, copy that tag name as the tag for Docker image. |
28 | | - IMAGE_TAGS: | |
29 | | - type=raw,value=dspace-7_x,enable=${{ endsWith(github.ref, github.event.repository.default_branch) }} |
30 | | - type=ref,event=branch,enable=${{ !endsWith(github.ref, github.event.repository.default_branch) }} |
31 | | - type=ref,event=tag |
32 | | - # Define default tag "flavor" for docker/metadata-action per |
33 | | - # https://github.com/docker/metadata-action#flavor-input |
34 | | - # We turn off 'latest' tag by default. |
35 | | - TAGS_FLAVOR: | |
36 | | - latest=false |
37 | | - # Architectures / Platforms for which we will build Docker images |
38 | | - # If this is a PR, we ONLY build for AMD64. For PRs we only do a sanity check test to ensure Docker builds work. |
39 | | - # If this is NOT a PR (e.g. a tag or merge commit), also build for ARM64. |
40 | | - PLATFORMS: linux/amd64${{ github.event_name != 'pull_request' && ', linux/arm64' || '' }} |
41 | 47 |
|
42 | 48 | steps: |
43 | 49 | # https://github.com/actions/checkout |
|
61 | 67 | username: ${{ secrets.DOCKER_USERNAME }} |
62 | 68 | password: ${{ secrets.DOCKER_ACCESS_TOKEN }} |
63 | 69 |
|
64 | | - ############################################### |
65 | | - # Build/Push the 'dspace/dspace-angular' image |
66 | | - ############################################### |
67 | 70 | # https://github.com/docker/metadata-action |
68 | 71 | # Get Metadata for docker_build step below |
69 | 72 | - name: Sync metadata (tags, labels) from GitHub to Docker for 'dspace-angular' image |
|
77 | 80 | # https://github.com/docker/build-push-action |
78 | 81 | - name: Build and push 'dspace-angular' image |
79 | 82 | id: docker_build |
80 | | - uses: docker/build-push-action@v3 |
| 83 | + uses: docker/build-push-action@v4 |
81 | 84 | with: |
82 | 85 | context: . |
83 | 86 | file: ./Dockerfile |
|
88 | 91 | # Use tags / labels provided by 'docker/metadata-action' above |
89 | 92 | tags: ${{ steps.meta_build.outputs.tags }} |
90 | 93 | labels: ${{ steps.meta_build.outputs.labels }} |
| 94 | + |
| 95 | + ############################################################# |
| 96 | + # Build/Push the 'dspace/dspace-angular' image ('-dist' tag) |
| 97 | + ############################################################# |
| 98 | + dspace-angular-dist: |
| 99 | + # Ensure this job never runs on forked repos. It's only executed for 'dspace/dspace-angular' |
| 100 | + if: github.repository == 'dspace/dspace-angular' |
| 101 | + runs-on: ubuntu-latest |
| 102 | + |
| 103 | + steps: |
| 104 | + # https://github.com/actions/checkout |
| 105 | + - name: Checkout codebase |
| 106 | + uses: actions/checkout@v3 |
| 107 | + |
| 108 | + # https://github.com/docker/setup-buildx-action |
| 109 | + - name: Setup Docker Buildx |
| 110 | + uses: docker/setup-buildx-action@v2 |
| 111 | + |
| 112 | + # https://github.com/docker/setup-qemu-action |
| 113 | + - name: Set up QEMU emulation to build for multiple architectures |
| 114 | + uses: docker/setup-qemu-action@v2 |
| 115 | + |
| 116 | + # https://github.com/docker/login-action |
| 117 | + - name: Login to DockerHub |
| 118 | + # Only login if not a PR, as PRs only trigger a Docker build and not a push |
| 119 | + if: github.event_name != 'pull_request' |
| 120 | + uses: docker/login-action@v2 |
| 121 | + with: |
| 122 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 123 | + password: ${{ secrets.DOCKER_ACCESS_TOKEN }} |
| 124 | + |
| 125 | + # https://github.com/docker/metadata-action |
| 126 | + # Get Metadata for docker_build_dist step below |
| 127 | + - name: Sync metadata (tags, labels) from GitHub to Docker for 'dspace-angular-dist' image |
| 128 | + id: meta_build_dist |
| 129 | + uses: docker/metadata-action@v4 |
| 130 | + with: |
| 131 | + images: dspace/dspace-angular |
| 132 | + tags: ${{ env.IMAGE_TAGS }} |
| 133 | + # As this is a "dist" image, its tags are all suffixed with "-dist". Otherwise, it uses the same |
| 134 | + # tagging logic as the primary 'dspace/dspace-angular' image above. |
| 135 | + flavor: ${{ env.TAGS_FLAVOR }} |
| 136 | + suffix=-dist |
| 137 | + |
| 138 | + - name: Build and push 'dspace-angular-dist' image |
| 139 | + id: docker_build_dist |
| 140 | + uses: docker/build-push-action@v4 |
| 141 | + with: |
| 142 | + context: . |
| 143 | + file: ./Dockerfile.dist |
| 144 | + platforms: ${{ env.PLATFORMS }} |
| 145 | + # For pull requests, we run the Docker build (to ensure no PR changes break the build), |
| 146 | + # but we ONLY do an image push to DockerHub if it's NOT a PR |
| 147 | + push: ${{ github.event_name != 'pull_request' }} |
| 148 | + # Use tags / labels provided by 'docker/metadata-action' above |
| 149 | + tags: ${{ steps.meta_build_dist.outputs.tags }} |
| 150 | + labels: ${{ steps.meta_build_dist.outputs.labels }} |
0 commit comments