|
| 1 | +name: Build and Push Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ master ] |
| 6 | + repository_dispatch: |
| 7 | + types: |
| 8 | + - dispatch-build |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +jobs: |
| 12 | + make-date-tag: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: startsWith(github.repository, 'opensciencegrid/') |
| 15 | + outputs: |
| 16 | + dtag: ${{ steps.mkdatetag.outputs.dtag }} |
| 17 | + steps: |
| 18 | + - name: make date tag |
| 19 | + id: mkdatetag |
| 20 | + run: echo "::set-output name=dtag::$(date +%Y%m%d-%H%M)" |
| 21 | + |
| 22 | + build: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + needs: [make-date-tag] |
| 25 | + if: startsWith(github.repository, 'opensciencegrid/') |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v2 |
| 28 | + |
| 29 | + - name: Generate tag list |
| 30 | + id: generate-tag-list |
| 31 | + env: |
| 32 | + TIMESTAMP: ${{ needs.make-date-tag.outputs.dtag }} |
| 33 | + run: | |
| 34 | + #docker_repo=${GITHUB_REPOSITORY/opensciencegrid\/docker-/opensciencegrid/} |
| 35 | + docker_repo=opensciencegrid/comanage-utils |
| 36 | + tag_list=() |
| 37 | + for registry in docker.io hub.opensciencegrid.org; do |
| 38 | + for image_tag in "latest" "latest-$TIMESTAMP"; do |
| 39 | + tag_list+=("$registry/$docker_repo":"$image_tag") |
| 40 | + done |
| 41 | + done |
| 42 | + # This causes the tag_list array to be comma-separated below, |
| 43 | + # which is required for build-push-action |
| 44 | + IFS=, |
| 45 | + echo "::set-output name=taglist::${tag_list[*]}" |
| 46 | +
|
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v1 |
| 49 | + |
| 50 | + - name: Log in to Docker Hub |
| 51 | + uses: docker/login-action@v1 |
| 52 | + with: |
| 53 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 54 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 55 | + |
| 56 | + - name: Log in to OSG Harbor |
| 57 | + uses: docker/login-action@v1 |
| 58 | + with: |
| 59 | + registry: hub.opensciencegrid.org |
| 60 | + username: ${{ secrets.OSG_HARBOR_ROBOT_USER }} |
| 61 | + password: ${{ secrets.OSG_HARBOR_ROBOT_PASSWORD }} |
| 62 | + |
| 63 | + - name: Build and push Docker images |
| 64 | + |
| 65 | + with: |
| 66 | + context: . |
| 67 | + push: true |
| 68 | + tags: "${{ steps.generate-tag-list.outputs.taglist }}" |
| 69 | + |
0 commit comments