Skip to content

Commit

Permalink
feat: support building pika_exporter docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengyu committed Mar 6, 2024
1 parent 299f166 commit a482575
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,19 @@
make_config.mk
log/
lib/
tools/
tools/aof_to_pika
tools/benchmark_client
tools/binlog_sender
tools/codis2pika
tools/kubeblocks_helm
tools/manifest_generator
tools/pika-port
tools/pika_keys_analysis
tools/pika_to_txt
tools/rdb_to_pika
tools/redis-copy
tools/txt_to_pika
docker/
output/

# DB
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/publish_nightly_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,41 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

push_pika_exporter_to_registry:
name: Push Pika Exporter Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: pikadb/pika-exporter-dev-nightly
tags: |
type=schedule,prefix={{branch}},pattern={{date 'YYYYMMDD'}}
- name: Build and push Docker image
timeout-minutes: 1440
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/Dockerfile_pika_exporter
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
36 changes: 36 additions & 0 deletions .github/workflows/publish_release_docker_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,39 @@ jobs:
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

push_pika_exporter_to_registry:
name: Push Pika Exporter Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: pikadb/pika-exporter

- name: Build and push Docker image
timeout-minutes: 1440
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
platforms: linux/amd64,linux/arm64
file: ./docker/Dockerfile_pika_exporter
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
35 changes: 35 additions & 0 deletions docker/Dockerfile_pika_exporter
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM golang:1.19 AS builder

LABEL maintainer="chengyu_l@126.com"

ENV PIKA=/pika \
PIKA_BUILD_DIR=/tmp/pika \
PATH=${PIKA}:${PIKA}/bin:${PATH} \
GO111MODULE=on \
GOPROXY=https://goproxy.cn

WORKDIR ${PIKA_BUILD_DIR}

COPY . ${PIKA_BUILD_DIR}

RUN echo `ls ${PIKA_BUILD_DIR}`

RUN make -C ${PIKA_BUILD_DIR}/tools/pika_exporter


FROM ubuntu:22.04

LABEL LABEL maintainer="chengyu_l@126.com"

ENV PIKA=/pika \
PIKA_BUILD_DIR=/tmp/pika \
PATH=${PIKA}:${PIKA}/bin:${PATH}

WORKDIR ${PIKA}

COPY --from=builder ${PIKA_BUILD_DIR}/tools/pika_exporter/bin/pika_exporter ${PIKA}/bin/pika_exporter
COPY --from=builder ${PIKA_BUILD_DIR}/tools/pika_exporter/config/info.toml ${PIKA}/conf/info.toml

EXPOSE 9121

CMD ["/pika/bin/pika_exporter", "--config", "/pika/conf/info.toml"]
89 changes: 89 additions & 0 deletions docker/build_pika_exporter_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#! /bin/bash

# parse arguments
# -t tag, default is "pikadb/pika-exporter:<git tag>"
# -p platform , it will use docker buildx, options: all, linux/amd64, linux/arm64, linux/arm, linux/arm64, darwin/amd64 more details: https://docs.docker.com/build/building/multi-platform/
# --help help

while getopts "t:p:-:" opt; do
case $opt in
t)
TAG=$OPTARG
;;
p)
PLATFORM=$OPTARG
MULTIARCHIVE=true
;;
-)
case $OPTARG in
help)
echo "Usage: build_docker.sh [-t tag] [-p platform] [--help]"
echo ""
echo "Options:"
echo " -t tag default is \"pikadb/pika-exporter:<git tag>\""
echo " -p <plat>,[<plat>] default is current docker platform. "
echo " options: all, linux/amd64, linux/arm, linux/arm64"
echo " more details: https://docs.docker.com/build/building/multi-platform "
echo " --help help"
echo ""
echo "eg:"
echo " ./build_docker.sh -p linux/amd64,linux/arm64 -t pikadb/pika-exporter:latest "
exit 0
;;

*)
echo "Unknown option --$OPTARG"
exit 1
;;
esac
;;
*)
echo "Unknown option -$opt"
exit 1
;;
esac
done


# if TAG is not set, set it "pikadb/pika-exporter"
if [ -z "$TAG" ]
then
TAG="pikadb/pika-exporter:$(git describe --tags --abbrev=0 --always)"
fi

# if Platform is "all", set it "linux/amd64,linux/arm64,linux/arm"
if [ "$PLATFORM" = "all" ]
then
PLATFORM="linux/amd64,linux/arm,linux/arm64"
fi

# if Platform is not set, set it "linux/amd64"
if [ -z "$PLATFORM" ]
then
PLATFORM="linux/amd64"
fi

# check if docker is installed
if ! [ -x "$(command -v docker)" ]; then
echo 'Error: docker is not installed.' >&2
exit 1
fi


if [ "$MULTIARCHIVE" = true ]
then
# check if `docker buildx inpsect pika-builder` is ok
if ! docker buildx inspect pika-builder > /dev/null 2>&1; then
docker buildx create --use --name=pika-builder --driver docker-container
else
docker buildx use pika-builder
fi

docker buildx build --platform ${PLATFORM} -t ${TAG} -f Dockerfile_pika_exporter ../

else
# build single-arch image
docker build -t ${TAG} -f Dockerfile_pika_exporter ../
fi


0 comments on commit a482575

Please sign in to comment.