diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml new file mode 100644 index 00000000..def05b10 --- /dev/null +++ b/.github/workflows/container-image.yml @@ -0,0 +1,28 @@ +name: Container Image + +on: + push: + branches: + - main + pull_request: {} + release: + types: + - published + +jobs: + container-image: + # Required by the base Container Image Action [^1]. + # [^1]: https://github.com/Icinga/github-actions/blob/main/.github/workflows/container-image.yml#L54-L58 + permissions: + contents: read + packages: write + attestations: write + id-token: write + + name: Build and Public Container Image + uses: icinga/github-actions/.github/workflows/container-image.yml@main + with: + documentation_url: https://icinga.com/docs/icinga-notifications + secrets: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index e52ce14b..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,45 +0,0 @@ -name: Docker - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - release: - types: [ published ] - -jobs: - docker: - runs-on: ubuntu-latest - steps: - - uses: docker/metadata-action@v6 - id: meta - with: - images: | - icinga/icinga-notifications - tags: | - type=ref,event=branch,enable={{is_default_branch}} - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - uses: docker/setup-qemu-action@v4 - - - uses: docker/setup-buildx-action@v4 - - - if: github.event_name != 'pull_request' - uses: docker/login-action@v4 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v7 - with: - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} - tags: ${{ steps.meta.outputs.tags }} - # Keep the .git to allow including the commit in the --version output, see also: - # https://docs.docker.com/build/building/context/#keep-git-directory - build-args: | - BUILDKIT_CONTEXT_KEEP_GIT_DIR=1 diff --git a/Containerfile b/Containerfile new file mode 100644 index 00000000..9c4e863b --- /dev/null +++ b/Containerfile @@ -0,0 +1,34 @@ +# Icinga Notifications | (c) 2023 Icinga GmbH | GPLv2+ + +FROM docker.io/library/golang AS base + +WORKDIR /icinga-notifications +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +FROM base AS build + +# The source code must be mounted in read-write mode to allow the makefile to temporarily create the build artifacts +# in the source directory. These artifacts will then directly be deleted after the build process is finished. +RUN --mount=type=bind,source=.,target=.,rw \ + --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + CGO_ENABLED=0 make all && \ + make test && \ + make DESTDIR=/target install && \ + make clean + +FROM docker.io/library/alpine AS runtime + +COPY --from=build /target / + +RUN apk add tzdata + +ARG username=notifications +RUN addgroup -g 1000 $username +RUN adduser -u 1000 -H -D -G $username $username +USER $username + +EXPOSE 5680 +CMD ["/usr/sbin/icinga-notifications"] diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index f04a576d..00000000 --- a/Dockerfile +++ /dev/null @@ -1,26 +0,0 @@ -# Icinga Notifications | (c) 2023 Icinga GmbH | GPLv2+ - -FROM docker.io/library/golang AS build -ENV CGO_ENABLED=0 -COPY . /src/icinga-notifications -WORKDIR /src/icinga-notifications - -RUN --mount=type=cache,target=/go/pkg/mod \ - --mount=type=cache,target=/root/.cache/go-build \ - make all - -RUN make DESTDIR=/target install - -FROM docker.io/library/alpine - -COPY --from=build /target / - -RUN apk add tzdata - -ARG username=notifications -RUN addgroup -g 1000 $username -RUN adduser -u 1000 -H -D -G $username $username -USER $username - -EXPOSE 5680 -CMD ["/usr/sbin/icinga-notifications"] diff --git a/doc/02-Installation.md.d/For-Container.md b/doc/02-Installation.md.d/For-Container.md new file mode 100644 index 00000000..c5bb543e --- /dev/null +++ b/doc/02-Installation.md.d/For-Container.md @@ -0,0 +1,7 @@ +# Installing Icinga Notifications in Containers + +This image integrates Icinga Notifications into your containerized environment. + +## Usage + +TODO...