Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
rwunderer committed Feb 27, 2024
1 parent 2b2539d commit 61e4e96
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/actions/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Build
description: Build vmauth image
inputs:
version:
description: version
required: true
tags:
description: image tags
required: true
runs:
using: "composite"
steps:
- name: Build image
env:
OPENSEARCH_VER: ${{ inputs.version }}
TAGS: ${{ inputs.tags }}
run: |
set -e
make
make test
. $GITHUB_ACTION_PATH/release.sh
shell: bash
17 changes: 17 additions & 0 deletions .github/actions/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash

set -e

if [[ "${GITHUB_REF}" == refs/heads/main || "${GITHUB_REF}" == refs/tags/* ]]; then
docker login ${DOCKER_REGISTRY} -u "${DOCKER_USERNAME}" -p "${DOCKER_PASSWORD}"

if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
export STABILITY_TAG="${GITHUB_REF##*/}"
fi

IFS=',' read -ra tags <<< "${TAGS}"

for tag in "${tags[@]}"; do
make release TAG="${tag}";
done
fi
24 changes: 24 additions & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Build docker image

on:
push:
branches:
- main

tags:
- '*'

env:
DOCKER_REGISTRY: ghcr.io
DOCKER_USERNAME: ${{ github.actor }}
DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }}

jobs:
vmauth-1:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/actions
with:
version: '1.93.11'
tags: 1.93.11,1.93,1,latest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
*.tar.gz
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
ARG VMAUTH_VER

FROM victoriametrics/vmauth:v${VMAUTH_VER}

ARG TARGETPLATFORM

RUN set -xe; \
apk add --update --no-cache \
bash \
make \
curl \
su-exec \
util-linux; \
\
dockerplatform=${TARGETPLATFORM:-linux/amd64};\
gotpl_url="https://github.com/wodby/gotpl/releases/download/0.3.3/gotpl-${TARGETPLATFORM/\//-}.tar.gz"; \
wget -O- "${gotpl_url}" | tar xz --no-same-owner -C /usr/local/bin; \
\
rm -rf /tmp/*; \
rm -rf /var/cache/apk/*

COPY templates /etc/gotpl/
COPY bin /usr/local/bin/

ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
53 changes: 53 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-include env_make

VMAUTH_VER ?= 1.93.11
VMAUTH_MINOR_VER=$(shell echo "${VMAUTH_VER}" | grep -oE '^[0-9]+\.[0-9]+')

# Remove minor version from tag
TAG ?= $(VMAUTH_MINOR_VER)

ifneq ($(STABILITY_TAG),)
ifneq ($(TAG),latest)
override TAG := $(TAG)-$(STABILITY_TAG)
endif
endif

REPO = ghcr.io/ramsalt/vmauth
NAME = vmauth-$(VMAUTH_MINOR_VER)

ENV = -e VICTORIA_METRICS_TOKEN=test-token

.PHONY: build test push shell run start stop logs clean release

default: build

build:
docker build -t $(REPO):$(TAG) \
--build-arg VMAUTH_VER=$(VMAUTH_VER) \
./

test:
cd ./tests && IMAGE=$(REPO):$(TAG) NAME=$(NAME) VMAUTH_VER=$(VMAUTH_VER) ./run.sh

push:
docker push $(REPO):$(TAG)

shell:
docker run --rm --name $(NAME) -i -t $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) /bin/bash

run:
docker run --rm -it --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG) $(CMD)

start:
docker run -d --name $(NAME) $(PORTS) $(VOLUMES) $(ENV) $(REPO):$(TAG)

stop:
docker stop $(NAME)

logs:
docker logs $(NAME)

clean:
-docker rm -f $(NAME)

release: build push
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# vmauth

Victoriametric vmauth container with custom config file
16 changes: 16 additions & 0 deletions bin/actions.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.PHONY: check-ready check-live

host ?= localhost
max_try ?= 1
wait_seconds ?= 1
delay_seconds ?= 0
command = curl -s -o /dev/null -H 'Authorization: Bearer ${VICTORIA_METRICS_TOKEN}' -I -w '%{http_code}' http://${host}:8427/debug/pprof/ | grep -q 200
service = vmauth

default: check-ready

check-ready:
wait_for "$(command)" $(service) $(host) $(max_try) $(wait_seconds) $(delay_seconds)

check-live:
@echo "OK"
15 changes: 15 additions & 0 deletions bin/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

if [[ -n "${DEBUG}" ]]; then
set -x
fi

mkdir -p /etc/vmauth
gotpl "/etc/gotpl/config.yml.tmpl" > /etc/vmauth/config.yml

if [[ "${1}" == 'make' ]]; then
exec "${@}" -f /usr/local/bin/actions.mk
else
exec /vmauth-prod -auth.config=/etc/vmauth/config.yml "${@}"
fi
37 changes: 37 additions & 0 deletions bin/wait_for
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash

set -e

if [[ -n "${DEBUG}" ]]; then
set -x
fi

if [ "$#" -lt 6 ]; then
echo "Illegal number of parameters"
fi

started=0
command=$1
service=$2
host=$3
max_try=$4
wait_seconds=$5
delay_seconds=$6

sleep "${delay_seconds}"

for i in $(seq 1 "${max_try}"); do
if eval "${command}"; then
started=1
break
fi
echo "${service} is starting..."
sleep "${wait_seconds}"
done

if [[ "${started}" -eq '0' ]]; then
echo >&2 "Error. ${service} is unreachable."
exit 1
fi

echo "${service} has started!"
4 changes: 4 additions & 0 deletions templates/config.yml.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
users:
- bearer_token: {{ getenv "VICTORIA_METRICS_TOKEN" }}
url_prefix:
- {{ getenv "VICTORIA_METRICS_URL" "http://victoria-metrics:8428/" }}
15 changes: 15 additions & 0 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "2"

services:
vmetrics:
environment:
VICTORIA_METRICS_TOKEN: test-token
image: victoriametrics/victoria-metrics:v$VMAUTH_VER

vmauth:
environment:
VICTORIA_METRICS_TOKEN: test-token
VICTORIA_METRICS_URL: http://tests-vmetrics-1:8428/
image: $IMAGE
depends_on:
- vmetrics
11 changes: 11 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

set -e

if [[ -n "${DEBUG}" ]]; then
set -x
fi

docker compose up -d
docker compose exec -T vmauth make check-ready wait_seconds=5 max_try=30 -f /usr/local/bin/actions.mk
docker compose down

0 comments on commit 61e4e96

Please sign in to comment.