2020-12-04 09:05:33 +00:00
|
|
|
name: Publish Docker image
|
2022-06-17 14:12:49 +00:00
|
|
|
|
2020-12-04 09:05:33 +00:00
|
|
|
on:
|
|
|
|
release:
|
|
|
|
types:
|
|
|
|
- released
|
|
|
|
- prereleased
|
2022-06-17 14:12:49 +00:00
|
|
|
|
2020-12-04 09:05:33 +00:00
|
|
|
jobs:
|
|
|
|
push_to_registry:
|
|
|
|
name: Push Docker image to Docker Hub
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Check out the repo
|
2022-04-05 09:00:11 +00:00
|
|
|
uses: actions/checkout@v3
|
2023-02-01 15:55:34 +00:00
|
|
|
with:
|
|
|
|
fetch-depth: 0
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Prepare
|
2020-12-04 09:05:33 +00:00
|
|
|
id: prep
|
|
|
|
run: |
|
|
|
|
DOCKER_IMAGE=crowdsecurity/crowdsec
|
2022-04-20 14:02:20 +00:00
|
|
|
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/crowdsec
|
2020-12-04 09:05:33 +00:00
|
|
|
VERSION=edge
|
|
|
|
if [[ $GITHUB_REF == refs/tags/* ]]; then
|
|
|
|
VERSION=${GITHUB_REF#refs/tags/}
|
|
|
|
elif [[ $GITHUB_REF == refs/heads/* ]]; then
|
2021-07-08 06:50:40 +00:00
|
|
|
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -E 's#/+#-#g')
|
2020-12-04 09:05:33 +00:00
|
|
|
elif [[ $GITHUB_REF == refs/pull/* ]]; then
|
|
|
|
VERSION=pr-${{ github.event.number }}
|
|
|
|
fi
|
2022-04-20 14:02:20 +00:00
|
|
|
TAGS="${DOCKER_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION}"
|
2022-11-08 11:28:57 +00:00
|
|
|
TAGS_SLIM="${DOCKER_IMAGE}:${VERSION}-slim"
|
2020-12-07 14:44:24 +00:00
|
|
|
if [[ ${{ github.event.action }} == released ]]; then
|
2022-04-20 14:02:20 +00:00
|
|
|
TAGS=$TAGS,${DOCKER_IMAGE}:latest,${GHCR_IMAGE}:latest
|
2023-01-09 15:44:03 +00:00
|
|
|
TAGS_SLIM=$TAGS_SLIM,${DOCKER_IMAGE}:slim
|
2020-12-07 14:44:24 +00:00
|
|
|
fi
|
2023-02-01 15:55:34 +00:00
|
|
|
echo "version=${VERSION}" >> $GITHUB_OUTPUT
|
|
|
|
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
|
|
|
|
echo "tags_slim=${TAGS_SLIM}" >> $GITHUB_OUTPUT
|
|
|
|
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Set up QEMU
|
|
|
|
uses: docker/setup-qemu-action@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
|
|
uses: docker/setup-buildx-action@v2
|
2023-03-01 09:56:25 +00:00
|
|
|
with:
|
|
|
|
config: .github/buildkit.toml
|
|
|
|
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Login to DockerHub
|
|
|
|
uses: docker/login-action@v2
|
2020-12-04 09:05:33 +00:00
|
|
|
with:
|
|
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
2022-04-20 14:02:20 +00:00
|
|
|
|
|
|
|
- name: Login to GitHub Container Registry
|
2023-02-01 15:55:34 +00:00
|
|
|
uses: docker/login-action@v2
|
2022-04-20 14:02:20 +00:00
|
|
|
with:
|
|
|
|
registry: ghcr.io
|
|
|
|
username: ${{ github.repository_owner }}
|
|
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
2022-11-08 11:28:57 +00:00
|
|
|
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Build and push slim image
|
2023-02-01 15:55:34 +00:00
|
|
|
uses: docker/build-push-action@v4
|
2022-11-08 11:28:57 +00:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
|
|
tags: ${{ steps.prep.outputs.tags_slim }}
|
2023-01-19 10:02:23 +00:00
|
|
|
target: slim
|
2022-11-08 11:28:57 +00:00
|
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386
|
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
|
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
|
|
|
org.opencontainers.image.revision=${{ github.sha }}
|
|
|
|
|
2023-01-04 15:55:34 +00:00
|
|
|
- name: Build and push full image
|
2023-02-01 15:55:34 +00:00
|
|
|
uses: docker/build-push-action@v4
|
2020-12-04 09:05:33 +00:00
|
|
|
with:
|
|
|
|
context: .
|
|
|
|
file: ./Dockerfile
|
|
|
|
push: ${{ github.event_name != 'pull_request' }}
|
|
|
|
tags: ${{ steps.prep.outputs.tags }}
|
2022-02-28 11:04:31 +00:00
|
|
|
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386
|
2020-12-04 09:05:33 +00:00
|
|
|
labels: |
|
|
|
|
org.opencontainers.image.source=${{ github.event.repository.html_url }}
|
|
|
|
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
|
2022-02-15 16:10:15 +00:00
|
|
|
org.opencontainers.image.revision=${{ github.sha }}
|