Skip to content

Commit

Permalink
🔨 fix docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed Mar 8, 2024
1 parent 368d1df commit 4d146e8
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 3 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/build-and-push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Build & push vMonitor-Metrics-Agent Docker Image
on:
workflow_dispatch:
inputs:
push_to_hub:
description: 'Publish docker image to dockerhub'
required: false
default: false
type: boolean
env:
REPO_NAME: ${{ github.event.repository.name }}
jobs:
build:
name: Build & push docker image
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create image name env
run: |
echo "IMG_NAME=${{ vars.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}" >> $GITHUB_ENV
- name: debug
run: |
echo ${{ env.IMG_NAME }}
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: |
${{ env.IMG_NAME }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=raw,value={{sha}},enable=${{ github.ref_type != 'tag' }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./docker
push: ${{ inputs.push_to_hub }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
build-alpine:
name: Build & push docker image Alpine
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create image name env
run: |
echo "IMG_NAME=${{ vars.DOCKERHUB_USERNAME }}/${{ env.REPO_NAME }}" >> $GITHUB_ENV
- name: debug
run: |
echo ${{ env.IMG_NAME }}
- name: Docker metadata
id: metadata
uses: docker/metadata-action@v4
with:
images: |
${{ env.IMG_NAME }}
tags: |
type=semver,pattern={{version}},suffix=-alpine
type=semver,pattern={{major}}.{{minor}},suffix=-alpine
type=raw,value={{sha}}-alpine,enable=${{ github.ref_type != 'tag' }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./docker/alpine
push: ${{ inputs.push_to_hub }}
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
10 changes: 9 additions & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build . --file Dockerfile --tag my-image-name:$(date +%s)
run: docker build ./docker --file Dockerfile --tag my-image-name:$(date +%s)

build-alpine:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image Alpine
run: docker build ./docker/alpine --file Dockerfile --tag my-image-name-alpine:$(date +%s)
6 changes: 4 additions & 2 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
name: "Semantic PR and Commit Messages"

on:
push:
branches: [ "release-1.26" ]
pull_request:
types: [opened, reopened, synchronize, edited]
branches:
- master

jobs:
semantic:
Expand Down
24 changes: 24 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM buildpack-deps:bullseye-curl

RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends iputils-ping snmp procps lm-sensors libcap2-bin && \
rm -rf /var/lib/apt/lists/*

ENV TELEGRAF_VERSION 1.26.0-2.0.2
RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) ARCH='amd64';; \
arm64) ARCH='arm64';; \
armhf) ARCH='armhf';; \
armel) ARCH='armel';; \
*) echo "Unsupported architecture: ${dpkgArch}"; exit 1;; \
esac && \
wget --no-verbose https://github.com/vngcloud/vmonitor-metrics-agent/releases/download/${TELEGRAF_VERSION}/telegraf_nightly_${ARCH}.deb && \
dpkg -i telegraf_nightly_${ARCH}.deb && \
rm -f telegraf_nightly_${ARCH}.deb*

EXPOSE 8125/udp 8092/udp 8094

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf"]
36 changes: 36 additions & 0 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM alpine:3.17

RUN echo 'hosts: files dns' >> /etc/nsswitch.conf
RUN apk add --no-cache iputils ca-certificates net-snmp-tools procps lm_sensors tzdata su-exec libcap && \
update-ca-certificates

ENV TELEGRAF_VERSION 1.26.0-2.0.2

RUN ARCH= && \
case "$(apk --print-arch)" in \
x86_64) ARCH='amd64';; \
aarch64) ARCH='arm64';; \
*) echo "Unsupported architecture: $(apk --print-arch)"; exit 1;; \
esac && \
set -ex && \
mkdir ~/.gnupg; \
echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf; \
apk add --no-cache --virtual .build-deps wget gnupg tar && \
wget --no-verbose https://github.com/vngcloud/vmonitor-metrics-agent/releases/download/${TELEGRAF_VERSION}/telegraf-nightly_static_linux_${ARCH}.tar.gz && \
mkdir -p /usr/src /etc/telegraf && \
tar -C /usr/src -xzf telegraf-nightly_static_linux_${ARCH}.tar.gz && \
mv /usr/src/telegraf*/etc/telegraf/telegraf.conf /etc/telegraf/ && \
mkdir /etc/telegraf/telegraf.d && \
cp -a /usr/src/telegraf*/usr/bin/telegraf /usr/bin/ && \
gpgconf --kill all && \
rm -rf *.tar.gz* /usr/src /root/.gnupg && \
apk del .build-deps && \
addgroup -S telegraf && \
adduser -S telegraf -G telegraf && \
chown -R telegraf:telegraf /etc/telegraf

EXPOSE 8125/udp 8092/udp 8094

COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["telegraf"]
15 changes: 15 additions & 0 deletions docker/alpine/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
set -e

if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi

if [ "$(id -u)" -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"

exec su-exec telegraf "$@"
fi
15 changes: 15 additions & 0 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -e

if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi

if [ $EUID -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"

exec setpriv --reuid telegraf --init-groups "$@"
fi

0 comments on commit 4d146e8

Please sign in to comment.