Switch to using GitHub container registry

Signed-off-by: Marcus Noble <github@marcusnoble.co.uk>
This commit is contained in:
Marcus Noble 2023-07-29 21:59:59 +01:00
parent c0163bd9af
commit cce5533437
Signed by: AverageMarcus
GPG Key ID: B8F2DB8A7AEBAF78
2 changed files with 30 additions and 62 deletions

View File

@ -6,66 +6,34 @@ on:
tags: tags:
- v* - v*
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs: jobs:
build: build-and-push-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps: steps:
- uses: actions/checkout@v2 - name: Checkout repository
uses: actions/checkout@v3
- name: Prepare - name: Log in to the Container registry
id: prepare uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
run: | with:
DOCKER_IMAGE=averagemarcus/tailscale-exporter registry: ${{ env.REGISTRY }}
DOCKER_PLATFORMS=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/386,linux/ppc64le,linux/s390x username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
VERSION=latest - name: Extract metadata (tags, labels) for Docker
if [[ $GITHUB_REF == refs/tags/* ]]; then id: meta
VERSION=${GITHUB_REF#refs/tags/} uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
fi with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
TAGS="--tag ${DOCKER_IMAGE}:${VERSION}" - name: Build and push Docker image
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
TAGS="$TAGS --tag ${DOCKER_IMAGE}:latest" with:
fi context: .
push: true
echo ::set-output name=tags::${TAGS} tags: ${{ steps.meta.outputs.tags }}
echo ::set-output name=platforms::${DOCKER_PLATFORMS} labels: ${{ steps.meta.outputs.labels }}
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v3
- name: Cache Docker layers
uses: actions/cache@v2
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Docker Buildx (build)
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--platform ${{ steps.prepare.outputs.platforms }} \
--output "type=image,push=false" \
${{ steps.prepare.outputs.tags }} \
.
- name: Docker Login
env:
DOCKER_USERNAME: averagemarcus
DOCKER_PASSWORD: ${{ secrets.DOCKER_TOKEN }}
run: |
echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin
- name: Docker Buildx (push)
run: |
docker buildx build \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--platform ${{ steps.prepare.outputs.platforms }} \
--output "type=image,push=true" \
${{ steps.prepare.outputs.tags }} \
.

View File

@ -23,7 +23,7 @@ The following environment variable can be used to configure the exporter:
```shell ```shell
export TAILSCALE_API_KEY="my-tailscale-api-key" export TAILSCALE_API_KEY="my-tailscale-api-key"
export TAILSCALE_TAILNET="my-tailnet.github" export TAILSCALE_TAILNET="my-tailnet.github"
docker run --rm -it -p 8080:8080 -e TAILSCALE_API_KEY -e TAILSCALE_TAILNET averagemarcus/tailscale-exporter:latest docker run --rm -it -p 8080:8080 -e TAILSCALE_API_KEY -e TAILSCALE_TAILNET ghcr.io/averagemarcus/tailscale-exporter:latest
``` ```
Then visit: [http://localhost:8080/metrics](http://localhost:8080/metrics) Then visit: [http://localhost:8080/metrics](http://localhost:8080/metrics)
@ -76,7 +76,7 @@ spec:
spec: spec:
containers: containers:
- name: tailscale-exporter - name: tailscale-exporter
image: averagemarcus/tailscale-exporter:latest image: ghcr.io/averagemarcus/tailscale-exporter:latest
imagePullPolicy: Always imagePullPolicy: Always
ports: ports:
- containerPort: 8080 - containerPort: 8080