|
| 1 | +name: SSH Container build and push |
| 2 | + |
| 3 | +on: [push] |
| 4 | + |
| 5 | +env: |
| 6 | + # TEST_TARGET: Name of the testing target in the Dockerfile |
| 7 | + TEST_TARGET: testing |
| 8 | + |
| 9 | + # DO_TEST - true to build and run unit tests, false to skip the tests |
| 10 | + DO_TEST: false |
| 11 | + |
| 12 | + # DO_PUSH - true to push to the HPE_DEPLOY_REPO, false to not push |
| 13 | + DO_PUSH: true |
| 14 | + |
| 15 | + # Container build arguments - tie these to Blake for testing |
| 16 | + USER_UID: 1060 |
| 17 | + USER_GID: 100 |
| 18 | + |
| 19 | + # Image name for the SSH container |
| 20 | + IMAGE_NAME: ssh-container |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + - uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + fetch-depth: 0 |
| 30 | + ref: ${{ github.event.pull_request.head.sha }} |
| 31 | + |
| 32 | + - name: Lowercase repository name for docker build |
| 33 | + id: lowercase-repository-name |
| 34 | + run: | |
| 35 | + echo "REPO_NAME=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV |
| 36 | +
|
| 37 | + - name: "Set tags for main/master" |
| 38 | + id: set_tags |
| 39 | + run: | |
| 40 | + echo "VERSION_TAG=$(./git-version-gen | grep -v UNKNOWN)" >> ${GITHUB_ENV} |
| 41 | + echo "TEST_TAG=$(git rev-parse HEAD)-test" >> ${GITHUB_ENV} |
| 42 | + echo "SHA_TAG=$(git rev-parse HEAD)" >> ${GITHUB_ENV} |
| 43 | + echo "${GITHUB_ENV}:" |
| 44 | + cat ${GITHUB_ENV} |
| 45 | + shell: bash |
| 46 | + |
| 47 | + - name: "Docker metadata" |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v5 |
| 50 | + with: |
| 51 | + images: | |
| 52 | + ghcr.io/${{ env.REPO_NAME }}-ssh-container |
| 53 | + tags: | |
| 54 | + # For merge to master branch, tag example: 'master' |
| 55 | + type=ref,event=branch |
| 56 | + # For PR event, tag example: 'pr-3' |
| 57 | + type=ref,event=pr |
| 58 | + # For PR event or merge event, tag example: 1.0.1.12-5667 |
| 59 | + type=raw,value=${{ env.VERSION_TAG }} |
| 60 | + # For PR event or merge, tag example: 566769e04d2436cf5f42ae4f46092c7dff6e668e |
| 61 | + type=raw,value=${{ env.SHA_TAG }} |
| 62 | + # For push to semver tag, tag example: 1.0.2 |
| 63 | + # This also sets 'latest'. |
| 64 | + type=semver,pattern={{version}} |
| 65 | + # For push to semver tag, tag example: 1.0 |
| 66 | + type=semver,pattern={{major}}.{{minor}} |
| 67 | +
|
| 68 | + - name: Docker login |
| 69 | + uses: docker/login-action@v3 |
| 70 | + with: |
| 71 | + registry: ghcr.io |
| 72 | + username: ${{ github.actor }} |
| 73 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + |
| 75 | + - name: Generate SSH keys for container build |
| 76 | + run: | |
| 77 | + cd ssh-container |
| 78 | + make ssh-keys client-keys |
| 79 | +
|
| 80 | + - name: Build the test Docker image |
| 81 | + if: ${{ env.DO_TEST == 'true' }} |
| 82 | + id: docker_build_test_target |
| 83 | + uses: docker/build-push-action@v6 |
| 84 | + with: |
| 85 | + context: ./ssh-container |
| 86 | + push: false |
| 87 | + target: ${{ env.TEST_TARGET }} |
| 88 | + tags: ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} |
| 89 | + build-args: | |
| 90 | + USER_UID=${{ env.USER_UID }} |
| 91 | + USER_GID=${{ env.USER_GID }} |
| 92 | +
|
| 93 | + - name: Run the Docker image unit tests |
| 94 | + if: ${{ env.DO_TEST == 'true' }} |
| 95 | + run: docker run ${{ env.IMAGE_NAME }}:${{ env.TEST_TAG }} |
| 96 | + |
| 97 | + - name: Build the final Docker image |
| 98 | + id: docker_build |
| 99 | + uses: docker/build-push-action@v6 |
| 100 | + with: |
| 101 | + context: ./ssh-container |
| 102 | + push: ${{ env.DO_PUSH == 'true' }} |
| 103 | + tags: ${{ steps.meta.outputs.tags }} |
| 104 | + build-args: | |
| 105 | + USER_UID=${{ env.USER_UID }} |
| 106 | + USER_GID=${{ env.USER_GID }} |
| 107 | +
|
| 108 | + - name: Peek at the docker images |
| 109 | + run: docker images | grep ${{ env.IMAGE_NAME }} |
| 110 | + |
| 111 | + create_release: |
| 112 | + needs: build |
| 113 | + if: startsWith(github.ref, 'refs/tags/v') |
| 114 | + runs-on: ubuntu-latest |
| 115 | + steps: |
| 116 | + - name: Checkout |
| 117 | + uses: actions/checkout@v4 |
| 118 | + with: |
| 119 | + fetch-tags: true |
| 120 | + fetch-depth: 0 |
| 121 | + - name: Repair tag |
| 122 | + run: git fetch -f origin ${{ github.ref }}:${{ github.ref }} |
| 123 | + - name: Verify that the tag is annotated |
| 124 | + run: if test x$(git for-each-ref ${{ github.ref }} | awk '{print $2}') = xtag; then /bin/true; else echo "\"${{ github.ref }}\" does not look like an annotated tag!"; /bin/false; fi |
| 125 | + - name: Release |
| 126 | + uses: softprops/action-gh-release@v1 |
| 127 | + with: |
| 128 | + #prerelease: true |
| 129 | + generate_release_notes: true |
| 130 | + |
0 commit comments