Skip to content

Dispatch build & push Docker Image #2

Dispatch build & push Docker Image

Dispatch build & push Docker Image #2

name: Dispatch build & push Docker Image
on:
workflow_dispatch:
inputs:
release_version:
description: "Release version"
required: true
type: string
push_to_hub:
description: "Publish docker image to dockerhub"
required: false
default: false
type: boolean
jobs:
build:
name: Build & push docker image
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- 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: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# - 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@v5
with:
build-args: |
ARG_VERSION=${{ inputs.release_version }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker
push: ${{ inputs.push_to_hub }}
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}
labels: ${{ steps.metadata.outputs.labels }}
build-alpine:
name: Build & push docker image Alpine
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/[email protected]
- 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: Log in to the GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# - 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@v5
with:
build-args: |
ARG_VERSION=${{ inputs.release_version }}
ARG_GITHUB_REPOSITORY=${{ github.repository }}
context: ./docker/alpine
push: ${{ inputs.push_to_hub }}
tags: |
ghcr.io/${{ github.repository_owner }}/telegraf:${{ inputs.release_version }}-alpine
ghcr.io/${{ github.repository_owner }}/telegraf:${{ github.sha }}-alpine
labels: ${{ steps.metadata.outputs.labels }}