|
| 1 | +name: fastly.falco |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - gatling/* |
| 7 | + - .github/workflows/fastly-falco.yaml |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + push: |
| 11 | + description: Push to docker registry |
| 12 | + required: true |
| 13 | + default: false |
| 14 | + type: boolean |
| 15 | + |
| 16 | +env: |
| 17 | + WORKSPACE: fastly-falco |
| 18 | + DOCKER_REPO: cloudkats |
| 19 | + DOCKER_IMAGE: fastly-falco |
| 20 | + GREP_VERSION: "FALCO_VERSION=" |
| 21 | + |
| 22 | +jobs: |
| 23 | + buildonpush: |
| 24 | + name: BuildOnPush |
| 25 | + runs-on: ubuntu-latest |
| 26 | + if: >- |
| 27 | + github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'true' |
| 28 | + || github.event_name == 'push' && (github.event.created == false && github.event.forced == false) |
| 29 | + steps: |
| 30 | + |
| 31 | + |
| 32 | + - name: Login to Registry |
| 33 | + run: | |
| 34 | + echo "${DOCKER_PASSWORD}" | docker login -u ${DOCKER_USERNAME} --password-stdin |
| 35 | + env: |
| 36 | + DOCKER_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} |
| 37 | + DOCKER_PASSWORD: ${{ secrets.DOCKERHUB_TOKEN }} |
| 38 | + |
| 39 | + - name: prepare |
| 40 | + id: prep |
| 41 | + working-directory: ${{ env.WORKSPACE }} |
| 42 | + run: | |
| 43 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 44 | + # Strip "v" prefix from tag name |
| 45 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 46 | +
|
| 47 | + IMAGE_ID="${DOCKER_REPO}/${DOCKER_IMAGE}" |
| 48 | +
|
| 49 | + echo "::set-output name=ACTION_RUN_URL::https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 50 | + echo "::set-output name=ACTION_WORKFLOW_URL::https://github.com/${{github.repository}}/actions/workflows/${{github.action}}.yml" |
| 51 | + echo "::set-output name=DOCKER_VERSION::$(cat Dockerfile | grep "FALCO_VERSION=" | tr "=" " " | awk '{print $3}')" |
| 52 | +
|
| 53 | + echo ::set-output name=version::${VERSION} |
| 54 | + echo ::set-output name=tag_date::$(date -u +'%Y-%m') |
| 55 | + echo ::set-output name=sha::${GITHUB_SHA::8} |
| 56 | + echo ::set-output name=image_id::${IMAGE_ID} |
| 57 | +
|
| 58 | + - name: build & push docker image |
| 59 | + working-directory: ${{ env.WORKSPACE }} |
| 60 | + env: |
| 61 | + IMAGE_ID: ${{ steps.prep.outputs.image_id }} |
| 62 | + IMAGE: ${{ env.DOCKER_IMAGE }} |
| 63 | + TAG_VERSION_DATE: ${{ steps.prep.outputs.tag_date }} |
| 64 | + TAG_VERSION_SHA: ${{ steps.prep.outputs.sha }} |
| 65 | + TAG_VERSION: ${{ steps.prep.outputs.version }} |
| 66 | + CREATED: ${{ steps.prep.outputs.tag_date }} |
| 67 | + BUILD_URL: ${{ steps.prep.outputs.action_run_url }} |
| 68 | + IMAGE_VERSION: ${{ steps.prep.outputs.docker_version }} |
| 69 | + run: | |
| 70 | + ../bin/build.sh |
| 71 | + ../bin/push.sh |
| 72 | +
|
| 73 | + - name: docker hub description |
| 74 | + uses: peter-evans/[email protected] |
| 75 | + with: |
| 76 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 77 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 78 | + repository: ${{ env.DOCKER_REPO }}/${{ env.DOCKER_IMAGE }} |
| 79 | + readme-filepath: ${{ env.WORKSPACE }}/README.md |
| 80 | + short-description: "Unoficial Docker image with Fastly Falco, a VCL testing tooling" |
| 81 | + |
| 82 | + build-on-merge-request: |
| 83 | + name: build-on-merge-request |
| 84 | + runs-on: ubuntu-latest |
| 85 | + if: >- |
| 86 | + github.event_name == 'workflow_dispatch' && github.event.inputs.push == 'false' |
| 87 | + || github.event_name == 'push' && (github.event.created == true || github.event.forced == true) |
| 88 | + steps: |
| 89 | + |
| 90 | + |
| 91 | + |
| 92 | + env: |
| 93 | + XDG_CONFIG_HOME: ${{ env.WORKSPACE }}/hadolint.yaml |
| 94 | + with: |
| 95 | + dockerfile: ${{ env.WORKSPACE }}/Dockerfile |
| 96 | + |
| 97 | + - name: prepare |
| 98 | + id: prep |
| 99 | + working-directory: ${{ env.WORKSPACE }} |
| 100 | + run: | |
| 101 | + VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') |
| 102 | + # Strip "v" prefix from tag name |
| 103 | + [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') |
| 104 | +
|
| 105 | + IMAGE_ID="${DOCKER_REPO}/${DOCKER_IMAGE}" |
| 106 | +
|
| 107 | + echo "::set-output name=ACTION_RUN_URL::https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}" |
| 108 | + echo "::set-output name=ACTION_WORKFLOW_URL::https://github.com/${{github.repository}}/actions/workflows/${{github.action}}.yml" |
| 109 | + echo "::set-output name=DOCKER_VERSION::$(cat Dockerfile | grep "$GREP_VERSION" | tr "=" " " | awk '{print $3}')" |
| 110 | +
|
| 111 | + echo ::set-output name=version::${VERSION} |
| 112 | + echo ::set-output name=tag_date::$(date -u +'%Y-%m') |
| 113 | + echo ::set-output name=sha::${GITHUB_SHA::8} |
| 114 | + echo ::set-output name=image_id::${IMAGE_ID} |
| 115 | +
|
| 116 | + - name: build |
| 117 | + working-directory: ${{ env.WORKSPACE }} |
| 118 | + env: |
| 119 | + IMAGE_ID: ${{ steps.prep.outputs.image_id }} |
| 120 | + IMAGE: ${{ env.DOCKER_IMAGE }} |
| 121 | + TAG_VERSION_DATE: ${{ steps.prep.outputs.tag_date }} |
| 122 | + TAG_VERSION_SHA: ${{ steps.prep.outputs.sha }} |
| 123 | + TAG_VERSION: ${{ steps.prep.outputs.version }} |
| 124 | + CREATED: ${{ steps.prep.outputs.tag_date }} |
| 125 | + BUILD_URL: ${{ steps.prep.outputs.action_run_url }} |
| 126 | + IMAGE_VERSION: ${{ steps.prep.outputs.docker_version }} |
| 127 | + run: | |
| 128 | + ../bin/build.sh |
0 commit comments