Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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.release.release" | ||
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') | ||
- | ||
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters