|
| 1 | +name: Container |
| 2 | + |
| 3 | +on: [workflow_call] |
| 4 | + |
| 5 | +jobs: |
| 6 | + production-image: |
| 7 | + runs-on: ubuntu-latest |
| 8 | + steps: |
| 9 | + - name: Checkout |
| 10 | + uses: actions/checkout@v4 |
| 11 | + - name: "set IS_VERSION_TAG" |
| 12 | + run: | |
| 13 | + echo "IS_VERSION_TAG=${{ github.ref_type == 'tag' && startsWith(github.ref_name, 'v') }}" >> $GITHUB_ENV |
| 14 | + # set defaults |
| 15 | + echo "IS_LATEST_TAG=false" >> $GITHUB_ENV |
| 16 | + - name: "set IS_LATEST_TAG" |
| 17 | + if: ( env.IS_VERSION_TAG ) |
| 18 | + run: | |
| 19 | + # find the latest version that is not ourself |
| 20 | + export LATEST_VERSION=$(git tag -l | grep -v '${{ github.ref_name }}' | sort -r --version-sort) |
| 21 | + # get major minor patch versions |
| 22 | + IFS='.' read -r latest_major latest_minor latest_patch << EOF |
| 23 | + $LATEST_VERSION |
| 24 | + EOF |
| 25 | + IFS='.' read -r tag_major tag_minor tag_patch << EOF |
| 26 | + ${{ github.ref_name }} |
| 27 | + EOF |
| 28 | + # remove leading v |
| 29 | + latest_major=$(echo $latest_major | cut -c2-) |
| 30 | + tag_major=$(echo $tag_major | cut -c2-) |
| 31 | + echo "$tag_major >= $latest_major" |
| 32 | + if [[ $tag_major -ge $latest_major && ($tag_minor -ne 0 || $tag_patch -ne 0) ]]; then |
| 33 | + # set this tag to latest and stable |
| 34 | + echo "IS_LATEST_TAG=true" >> $GITHUB_ENV |
| 35 | + fi |
| 36 | + - name: "Setup meta information (IS_VERSION_TAG: ${{ env.IS_VERSION_TAG }}, IS_LATEST_TAG: ${{ env.IS_LATEST_TAG }} )" |
| 37 | + id: meta |
| 38 | + uses: docker/metadata-action@v5 |
| 39 | + with: |
| 40 | + images: ${{ github.repository }} |
| 41 | + labels: | |
| 42 | + org.opencontainers.image.vendor=Greenbone |
| 43 | + org.opencontainers.image.base.name=greenbone/gvm-libs |
| 44 | + flavor: latest=false # no auto latest container tag for git tags |
| 45 | + tags: | |
| 46 | + # when IS_LATEST_TAG is set create a stable and a latest tag |
| 47 | + type=raw,value=latest,enable=${{ env.IS_LATEST_TAG }} |
| 48 | + type=raw,value=stable,enable=${{ env.IS_LATEST_TAG }} |
| 49 | + # if tag version is set than create a version tags |
| 50 | + type=semver,pattern={{version}},enable=${{ env.IS_VERSION_TAG }} |
| 51 | + type=semver,pattern={{major}}.{{minor}},enable=${{ env.IS_VERSION_TAG }} |
| 52 | + type=semver,pattern={{major}},enable=${{ env.IS_VERSION_TAG }} |
| 53 | + # if we are on the main branch set edge |
| 54 | + type=edge,branch=main |
| 55 | + # use branch-sha otherwise for pushes to branches other then main (will not be uploaded) |
| 56 | + type=raw,value={{branch}}-{{sha}},enable=${{ github.ref_type == 'branch' && github.event_name == 'push' && github.ref_name != 'main' }} |
| 57 | + # use pr-$PR_ID for pull requests (will not be uploaded) |
| 58 | + type=ref,event=pr |
| 59 | + - name: Login to DockerHub |
| 60 | + if: github.event_name != 'pull_request' |
| 61 | + uses: docker/login-action@v3 |
| 62 | + with: |
| 63 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 64 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 65 | + |
| 66 | + - uses: actions/download-artifact@v3 |
| 67 | + with: |
| 68 | + name: rs-binaries |
| 69 | + path: assets |
| 70 | + - run: mkdir -p assets/linux/amd64 |
| 71 | + - run: mkdir -p assets/linux/arm64 |
| 72 | + - run: mv assets/openvasd-aarch64-unknown-linux-gnu assets/linux/arm64/openvasd |
| 73 | + - run: mv assets/openvasd-x86_64-unknown-linux-gnu assets/linux/amd64/openvasd |
| 74 | + - run: mv assets/nasl-cli-aarch64-unknown-linux-gnu assets/linux/arm64/nasl-cli |
| 75 | + - run: mv assets/nasl-cli-x86_64-unknown-linux-gnu assets/linux/amd64/nasl-cli |
| 76 | + - name: Set up QEMU |
| 77 | + uses: docker/setup-qemu-action@v3 |
| 78 | + - name: Set up Docker Buildx |
| 79 | + uses: docker/setup-buildx-action@v3 |
| 80 | + - name: Build and push |
| 81 | + uses: docker/build-push-action@v5 |
| 82 | + with: |
| 83 | + context: . |
| 84 | + push: ${{ github.event_name != 'pull_request' && (github.ref_type == 'tag' || github.ref_name == 'main') }} |
| 85 | + file: .docker/prod.Dockerfile |
| 86 | + build-args: | |
| 87 | + REPOSITORY=${{ github.repository }} |
| 88 | + platforms: linux/amd64,linux/aarch64 |
| 89 | + tags: ${{ steps.meta.outputs.tags }} |
| 90 | + labels: ${{ steps.meta.outputs.labels }} |
| 91 | + |
| 92 | + - name: "Setup meta information debian:oldstable" |
| 93 | + id: old_stable_meta |
| 94 | + uses: docker/metadata-action@v5 |
| 95 | + with: |
| 96 | + images: ${{ github.repository }} |
| 97 | + labels: | |
| 98 | + org.opencontainers.image.vendor=Greenbone |
| 99 | + org.opencontainers.image.base.name=greenbone/gvm-libs |
| 100 | + flavor: latest=false # no auto latest container tag for git tags |
| 101 | + tags: | |
| 102 | + # for the images provided for debian:oldstable we just provide |
| 103 | + # oldstable on an new version or oldstable-edge when it is on main. |
| 104 | + # oldstable-branch-sha on a branch |
| 105 | + type=raw,value=oldstable,enable=${{ env.IS_LATEST_TAG }} |
| 106 | + type=raw,value=oldstable-edge,enable=${{ github.ref_name == 'main' }} |
| 107 | + type=raw,value=oldstable-{{branch}}-{{sha}},enable=${{ github.ref_type == 'branch' && github.event_name == 'push' && github.ref_name != 'main' }} |
| 108 | + type=ref,event=pr |
| 109 | + - name: Build and push Container image |
| 110 | + uses: docker/build-push-action@v5 |
| 111 | + with: |
| 112 | + context: . |
| 113 | + push: ${{ github.event_name != 'pull_request' && (github.ref_type == 'tag' || github.ref_name == 'main') }} |
| 114 | + file: .docker/prod-oldstable.Dockerfile |
| 115 | + platforms: linux/amd64,linux/arm64 |
| 116 | + tags: ${{ steps.old_stable_meta.outputs.tags }} |
| 117 | + labels: ${{ steps.old_stable_meta.outputs.labels }} |
| 118 | + |
| 119 | + - name: "Setup meta information debian:testing" |
| 120 | + id: test_meta |
| 121 | + uses: docker/metadata-action@v5 |
| 122 | + with: |
| 123 | + images: ${{ github.repository }} |
| 124 | + labels: | |
| 125 | + org.opencontainers.image.vendor=Greenbone |
| 126 | + org.opencontainers.image.base.name=greenbone/gvm-libs |
| 127 | + flavor: latest=false # no auto latest container tag for git tags |
| 128 | + tags: | |
| 129 | + # for the images provided for debian:testing we just provide |
| 130 | + # testing on an new version or testing-edge when it is on main. |
| 131 | + # testing-branch-sha on a branch |
| 132 | + type=raw,value=testing,enable=${{ env.IS_LATEST_TAG }} |
| 133 | + type=raw,value=testing-edge,enable=${{ github.ref_name == 'main' }} |
| 134 | + type=raw,value=testing-{{branch}}-{{sha}},enable=${{ github.ref_type == 'branch' && github.event_name == 'push' && github.ref_name != 'main' }} |
| 135 | + type=ref,event=pr |
| 136 | + - name: Build and push Container image |
| 137 | + uses: docker/build-push-action@v5 |
| 138 | + with: |
| 139 | + context: . |
| 140 | + push: ${{ github.event_name != 'pull_request' && (github.ref_type == 'tag' || github.ref_name == 'main') }} |
| 141 | + file: .docker/prod-testing.Dockerfile |
| 142 | + platforms: linux/amd64,linux/arm64 |
| 143 | + tags: ${{ steps.test_meta.outputs.tags }} |
| 144 | + labels: ${{ steps.test_meta.outputs.labels }} |
0 commit comments