f8054e1f32
Co-authored-by: AlteredCoder <AlteredCoder>
70 lines
2.4 KiB
YAML
70 lines
2.4 KiB
YAML
name: Publish Docker image
|
|
on:
|
|
release:
|
|
types:
|
|
- released
|
|
- prereleased
|
|
jobs:
|
|
push_to_registry:
|
|
name: Push Docker image to Docker Hub
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
-
|
|
name: Check out the repo
|
|
uses: actions/checkout@v2
|
|
-
|
|
name: Prepare
|
|
id: prep
|
|
run: |
|
|
DOCKER_IMAGE=crowdsecurity/crowdsec
|
|
VERSION=edge
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
|
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
|
|
elif [[ $GITHUB_REF == refs/pull/* ]]; then
|
|
VERSION=pr-${{ github.event.number }}
|
|
fi
|
|
TAGS="${DOCKER_IMAGE}:${VERSION}"
|
|
echo ::set-output name=docker_image::${DOCKER_IMAGE}
|
|
echo ::set-output name=version::${VERSION}
|
|
echo ::set-output name=tags::${TAGS}
|
|
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
-
|
|
name: Tag Latest
|
|
id: prep_tag_latest
|
|
if: " github.event.action == 'released' "
|
|
run: |
|
|
TAGS=${{ steps.prep.outputs.tags }},${{ steps.prep.outputs.docker_image }}:latest
|
|
echo ::set-output name=tags::${TAGS}
|
|
echo ::set-output name=version::${{ steps.prep.outputs.version }}
|
|
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
- run: echo $ACTION
|
|
name: debug event.action
|
|
env:
|
|
ACTION: ${{ github.event.action }}
|
|
- run: echo $ACTION
|
|
name: debug event_name
|
|
env:
|
|
ACTION: ${{ github.event_name }}
|
|
-
|
|
name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
-
|
|
name: Login to DockerHub
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
-
|
|
name: Build and push
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
tags: ${{ steps.prep.outputs.tags }}
|
|
labels: |
|
|
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
|
org.opencontainers.image.revision=${{ github.sha }} |