|
| 1 | +name: Publish Docker image |
| 2 | +on: |
| 3 | + push: |
| 4 | + tags: |
| 5 | + - v* |
| 6 | +jobs: |
| 7 | + push_to_registry: |
| 8 | + name: Push Docker image to Docker Hub |
| 9 | + runs-on: ubuntu-latest |
| 10 | + steps: |
| 11 | + - |
| 12 | + name: Check out the repo |
| 13 | + uses: actions/checkout@v2 |
| 14 | + - |
| 15 | + name: Prepare |
| 16 | + id: prep |
| 17 | + run: | |
| 18 | + DOCKER_IMAGE=chaspy/aws-ecr-image-scan-findings-prometheus-exporter |
| 19 | + VERSION=edge |
| 20 | + if [[ $GITHUB_REF == refs/tags/* ]]; then |
| 21 | + VERSION=${GITHUB_REF#refs/tags/} |
| 22 | + elif [[ $GITHUB_REF == refs/heads/* ]]; then |
| 23 | + VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g') |
| 24 | + elif [[ $GITHUB_REF == refs/pull/* ]]; then |
| 25 | + VERSION=pr-${{ github.event.number }} |
| 26 | + fi |
| 27 | + TAGS="${DOCKER_IMAGE}:${VERSION}" |
| 28 | + if [ "${{ github.event_name }}" = "push" ]; then |
| 29 | + TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" |
| 30 | + fi |
| 31 | + echo ::set-output name=version::${VERSION} |
| 32 | + echo ::set-output name=tags::${TAGS} |
| 33 | + echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') |
| 34 | + - |
| 35 | + name: Set up Docker Buildx |
| 36 | + uses: docker/setup-buildx-action@v1 |
| 37 | + - |
| 38 | + name: Login to DockerHub |
| 39 | + uses: docker/login-action@v1 |
| 40 | + with: |
| 41 | + username: ${{ secrets.DOCKER_USERNAME }} |
| 42 | + password: ${{ secrets.DOCKER_PASSWORD }} |
| 43 | + - |
| 44 | + name: Build and push |
| 45 | + uses: docker/build-push-action@v2 |
| 46 | + with: |
| 47 | + context: . |
| 48 | + file: ./Dockerfile |
| 49 | + push: ${{ github.event_name != 'pull_request' }} |
| 50 | + tags: ${{ steps.prep.outputs.tags }} |
| 51 | + cache-from: type=registry,ref=chaspy/aws-ecr-image-scan-findings-prometheus-exporter:latest |
| 52 | + cache-to: type=inline |
0 commit comments