diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000..e9e6421 --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,46 @@ +name: Publish Docker image to GHCR on a new version + +on: + push: + branches: + - main + - dockertest +# tags: +# - [0-9]+.* + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + test_quality: + uses: ./.github/workflows/quality.yml + build_and_publish: + runs-on: ubuntu-latest + steps: + - name: Checkout sources + uses: actions/checkout@v4 + - name: Log in to the container registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GHCR_PAT }} + - name: Extract metadata (tags, labels) + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{ version }} + type=ref,event=branch + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} + type=sha + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + diff --git a/.github/workflows/quality.yml b/.github/workflows/quality.yml index a56c573..7b01f6f 100644 --- a/.github/workflows/quality.yml +++ b/.github/workflows/quality.yml @@ -1,7 +1,8 @@ --- -name: Pylint +name: Pylint Quality control -on: [push] +on: + workflow_call jobs: build: diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fa8d9c4 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +# syntax=docker/dockerfile:1 +FROM python:3.12-alpine +RUN mkdir -p /opt/netbox-zabbix +COPY . /opt/netbox-zabbix +WORKDIR /opt/netbox-zabbix +RUN if ! [ -f ./config.py ]; then cp ./config.py.example ./config.py; fi +RUN pip install -r ./requirements.txt +ENTRYPOINT ["python"] +CMD ["/opt/netbox-zabbix/netbox_zabbix_sync.py", "-v"] diff --git a/README.md b/README.md index 7674a71..67fa514 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,33 @@ A script to create, update and delete Zabbix hosts using Netbox device objects. -## Installation +## Installation via Docker + +To pull the latest stable version to your local cache, use the following docker pull command: +``` +docker pull ghcr.io/TheNetworkGuy/netbox-zabbix-sync:latest +``` + +Make sure to specify the needed environment variables for the script to work (see [here](#set-environment-variables)) +on the command line or use an [env file](https://docs.docker.com/reference/cli/docker/container/run/#env). + +``` +docker run -d -t -i -e ZABBIX_HOST='https://zabbix.local' \ +-e ZABBIX_TOKEN='othersecrettoken' \ +-e NETBOX_HOST='https://netbox.local' \ +-e NETBOX_TOKEN='secrettoken' \ +--name netbox-zabbix-sync ghcr.io/TheNetworkGuy/netbox-zabbix-sync:latest +``` + +This should run a one-time sync, you can check the sync with `docker logs netbox-zabbix-sync`. + +The image uses the default `config.py` for it's configuration, you can use a volume mount in the docker run command +to override with your own config file if needed (see [config file](#config-file)): +``` +docker run -d -t -i -v $(pwd)/config.py:/opt/netbox-zabbix/config.py ... +``` + +## Installation from Source ### Cloning the repository ```