|
| 1 | +--- |
| 2 | + |
1 | 3 | name: Create packages
|
2 |
| -on: |
3 |
| - pull_request: |
| 4 | + |
| 5 | +"on": |
| 6 | + push: |
4 | 7 | branches:
|
| 8 | + - develop |
5 | 9 | - main
|
6 |
| - types: |
7 |
| - - closed |
8 |
| - |
| 10 | + - testing-github-actions |
9 | 11 |
|
10 | 12 | jobs:
|
11 |
| - main: |
12 |
| - if: github.event.pull_request.merged == true |
| 13 | + tag: |
| 14 | + name: generate tag |
| 15 | + outputs: |
| 16 | + part: ${{ steps.generate_tag.outputs.part }} |
| 17 | + tag: ${{ steps.generate_tag.outputs.tag }} |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + with: |
| 22 | + fetch-depth: '1' |
| 23 | + - name: Generate new tag |
| 24 | + id: generate_tag |
| 25 | + uses: anothrNick/github-tag-action@1.61.0 |
| 26 | + env: |
| 27 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + WITH_V: true |
| 29 | + DEFAULT_BUMP: | |
| 30 | + ${{ |
| 31 | + github.ref_name == 'develop' && 'patch' || 'minor' |
| 32 | + }} |
| 33 | + DRY_RUN: true |
| 34 | + |
| 35 | + push_to_registry: |
| 36 | + strategy: |
| 37 | + matrix: |
| 38 | + include: |
| 39 | + - web_url: "https://urdr.nbis.se" |
| 40 | + redmine_url: "https://projects.nbis.se" |
| 41 | + env: "prod" |
| 42 | + - web_url: "https://urdr-test.nbis.se" |
| 43 | + redmine_url: "https://urdr-test-redmine.nbis.se" |
| 44 | + env: "test" |
| 45 | + needs: tag |
| 46 | + if: needs.tag.outputs.part != '' |
| 47 | + name: Push Docker image to Github Container registry |
13 | 48 | runs-on: ubuntu-latest
|
14 | 49 | permissions:
|
15 | 50 | contents: read
|
16 | 51 | packages: write
|
17 | 52 |
|
18 | 53 | steps:
|
19 |
| - - name: Checkout |
20 |
| - uses: actions/checkout@v2 |
| 54 | + - name: Check out the repo |
| 55 | + uses: actions/checkout@v4 |
21 | 56 |
|
22 |
| - - name: Build and push images |
23 |
| - working-directory: production |
24 |
| - env: |
25 |
| - DOCKER_BUILDKIT: 1 |
26 |
| - COMPOSE_DOCKER_CLI_BUILD: 1 |
27 |
| - GH_ACTOR: ${{ github.actor }} |
28 |
| - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
29 |
| - GH_HEAD_REF: ${{ github.head_ref }} |
| 57 | + - name: Set environment variables |
30 | 58 | run: |
|
31 |
| - echo "${GH_TOKEN}" | docker login ghcr.io -u "${GH_ACTOR}" --password-stdin |
32 |
| - branch="${GH_HEAD_REF}" |
33 |
| -
|
34 |
| - for image in urdr urdr-web; do |
35 |
| - docker pull "ghcr.io/nbisweden/$image:latest" || true |
36 |
| - docker pull "ghcr.io/nbisweden/$image:$branch" || true |
37 |
| - done |
38 |
| -
|
39 |
| - cat > urdr.env <<END |
40 |
| - PUBLIC_API_URL="https://urdr.nbis.se" |
41 |
| - PUBLIC_REDMINE_URL="https://projects.nbis.se" |
42 |
| - END |
43 |
| -
|
44 |
| - TAG="$branch" docker-compose --env-file urdr.env build --build-arg BUILDKIT_INLINE_CACHE=1 |
45 |
| -
|
46 |
| - for image in urdr urdr-web; do |
47 |
| - docker push "ghcr.io/nbisweden/$image:$branch" |
48 |
| - docker tag "ghcr.io/nbisweden/$image:$branch" "ghcr.io/nbisweden/$image:latest" |
49 |
| - docker push "ghcr.io/nbisweden/$image:latest" |
50 |
| - done |
| 59 | + GIT_BRANCH=${GITHUB_REF#refs/heads/} |
| 60 | + GIT_HASH=$(printf '%s\n' "$GITHUB_SHA" | cut -c -7) |
| 61 | + printf 'GIT_BRANCH=%s\n' "$GIT_BRANCH" >>"$GITHUB_ENV" |
| 62 | + printf 'GIT_HASH=%s\n' "$GIT_HASH" >>"$GITHUB_ENV" |
| 63 | +
|
| 64 | + - name: Log in to the Github Container registry |
| 65 | + uses: docker/login-action@v3 |
| 66 | + with: |
| 67 | + registry: ghcr.io |
| 68 | + username: ${{ github.actor }} |
| 69 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 70 | + |
| 71 | + - name: Extract metadata (tags, labels) for Docker |
| 72 | + id: meta |
| 73 | + uses: docker/metadata-action@v5 |
| 74 | + with: |
| 75 | + images: | |
| 76 | + ghcr.io/nbisweden/urdr |
| 77 | + ghcr.io/nbisweden/urdr-web |
| 78 | +
|
| 79 | + - name: Build and push urdr |
| 80 | + uses: docker/build-push-action@v5 |
| 81 | + with: |
| 82 | + context: ./backend |
| 83 | + file: ./production/Dockerfile |
| 84 | + push: true |
| 85 | + tags: | |
| 86 | + ghcr.io/nbisweden/urdr:${{ |
| 87 | + matrix.env == 'prod' && needs.tag.outputs.tag || |
| 88 | + format('{0}-test', needs.tag.outputs.tag) |
| 89 | + }} |
| 90 | + ghcr.io/nbisweden/urdr:latest |
| 91 | + labels: | |
| 92 | + org.opencontainers.image.source=${{ |
| 93 | + github.event.repository.clone_url |
| 94 | + }} |
| 95 | + org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 96 | + org.opencontainers.image.revision=${{ github.sha }} |
| 97 | +
|
| 98 | + - name: Build and push urdr-web |
| 99 | + uses: docker/build-push-action@v5 |
| 100 | + with: |
| 101 | + context: ./frontend |
| 102 | + file: ./production/Dockerfile.nginx |
| 103 | + build-args: | |
| 104 | + PUBLIC_API_URL=${{ matrix.web_url }} |
| 105 | + PUBLIC_REDMINE_URL=${{ matrix.redmine_url }} |
| 106 | + GIT_BRANCH=${{ env.GIT_BRANCH }} |
| 107 | + GIT_HASH=${{ env.GIT_HASH }} |
| 108 | + push: true |
| 109 | + tags: | |
| 110 | + ghcr.io/nbisweden/urdr-web:${{ |
| 111 | + matrix.env == 'prod' && needs.tag.outputs.tag || |
| 112 | + format('{0}-test', needs.tag.outputs.tag) |
| 113 | + }} |
| 114 | + ghcr.io/nbisweden/urdr-web:latest |
| 115 | + labels: | |
| 116 | + org.opencontainers.image.source=${{ |
| 117 | + github.event.repository.clone_url |
| 118 | + }} |
| 119 | + org.opencontainers.image.created=$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 120 | + org.opencontainers.image.revision=${{ github.sha }} |
| 121 | +
|
| 122 | + publish_tag: |
| 123 | + name: publish tag |
| 124 | + needs: [push_to_registry, tag] |
| 125 | + runs-on: ubuntu-latest |
| 126 | + steps: |
| 127 | + - uses: actions/checkout@v4 |
| 128 | + with: |
| 129 | + fetch-depth: '1' |
| 130 | + - name: Push tag |
| 131 | + id: push_tag |
| 132 | + uses: anothrNick/github-tag-action@1.61.0 |
| 133 | + env: |
| 134 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 135 | + CUSTOM_TAG: ${{ needs.tag.outputs.tag }} |
0 commit comments