Skip to content

Commit

Permalink
🌱 add build-package flow
Browse files Browse the repository at this point in the history
  • Loading branch information
anngdinh committed Jun 26, 2024
1 parent 1435135 commit a9929fe
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 52 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/build-package.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Build and Release package
on:
push:
# Pattern matched against refs/tags
tags:
- "**" # Push events to every tag including hierarchical tags like v1.0/beta

jobs:
create_release:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
steps:
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: |
gh release create "${{ github.ref_name }}" \
--repo="$GITHUB_REPOSITORY" \
--title="${{ github.ref_name }}" \
--generate-notes
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/[email protected]

- name: Install dependencies
run: sudo apt -y install rubygems && sudo gem install fpm && sudo apt install binutils && sudo apt-get install rpm -y

- name: Clear build directory
run: rm -rf ./build/

- name: Build
run: NIGHTLY=vmonitor make package include_packages="freebsd_amd64.tar.gz linux_amd64.tar.gz amd64.deb x86_64.rpm"
# run: NIGHTLY=vmonitor make package include_packages="freebsd_amd64.tar.gz linux_amd64.tar.gz amd64.deb x86_64.rpm linux_arm64.tar.gz arm64.deb aarch64.rpm freebsd_i386.tar.gz i386.deb linux_i386.tar.gz i386.rpm"

# - name: Install Windows dependencies
# run: go install github.com/josephspurrier/goversioninfo/cmd/goversioninfo@latest && export PATH=~/go/bin

# - name: Build Windows package
# run: NIGHTLY=vmonitor make package include_packages="windows_amd64.zip"
# # run: NIGHTLY=vmonitor make package include_packages="windows_i386.zip windows_amd64.zip windows_arm64.zip"

- name: Debug
run: ls -al ./build/dist/

- name: Upload files to a GitHub release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ github.ref_name }}
run: for file in ./build/dist/*; do gh release upload "${{ github.ref_name }}" "$file" --repo="$GITHUB_REPOSITORY"; done

############## build and upload image
- name: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ github.ref_name }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.ref_name }}
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}
# labels: ${{ steps.metadata.outputs.labels }}

- name: Build and push Docker image Alpine
uses: docker/build-push-action@v5
with:
build-args: |
ARG_VERSION=${{ github.ref_name }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker/alpine
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.ref_name }}-alpine
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}-alpine
# labels: ${{ steps.metadata.outputs.labels }}
48 changes: 0 additions & 48 deletions .github/workflows/ci.yaml

This file was deleted.

11 changes: 9 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ 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
ARG ARG_VERSION
ENV TELEGRAF_VERSION $ARG_VERSION

ARG ARG_GITHUB_REPOSITORY
ENV GITHUB_REPOSITORY $ARG_GITHUB_REPOSITORY

RUN echo ${TELEGRAF_VERSION}

RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
case "${dpkgArch##*-}" in \
amd64) ARCH='amd64';; \
Expand All @@ -13,7 +20,7 @@ RUN ARCH= && dpkgArch="$(dpkg --print-architecture)" && \
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 && \
wget --no-verbose https://github.com/${GITHUB_REPOSITORY}/releases/download/${TELEGRAF_VERSION}/telegraf_nightly_${ARCH}.deb && \
dpkg -i telegraf_nightly_${ARCH}.deb && \
rm -f telegraf_nightly_${ARCH}.deb*

Expand Down
8 changes: 6 additions & 2 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ 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
ARG ARG_VERSION
ENV TELEGRAF_VERSION $ARG_VERSION

ARG ARG_GITHUB_REPOSITORY
ENV GITHUB_REPOSITORY $ARG_GITHUB_REPOSITORY

RUN ARCH= && \
case "$(apk --print-arch)" in \
Expand All @@ -16,7 +20,7 @@ RUN ARCH= && \
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 && \
wget --no-verbose https://github.com/${GITHUB_REPOSITORY}/releases/download/${TELEGRAF_VERSION}/telegraf-nightly_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/ && \
Expand Down

0 comments on commit a9929fe

Please sign in to comment.