Skip to content

feat(release): push images to Docker Hub #10

feat(release): push images to Docker Hub

feat(release): push images to Docker Hub #10

name: Build and Push Docker Image
env:
IMAGE_NAME: nodebuilder
on:
release:
types: [ published ]
workflow_dispatch:
pull_request:
branches: [ push_docker_images_test ]
jobs:
build-and-push:
name : Push ${{ matrix.config.container }} image
runs-on: ubuntu-latest
strategy:
matrix:
config:
- {container: 'alpine', dockerfile: 'Dockerfile_alpine'}
- {container: 'amazon', dockerfile: 'Dockerfile_amazon'}
- {container: 'arch', dockerfile: 'Dockerfile_arch'}
- {container: 'debian', dockerfile: 'Dockerfile_debian'}
- {container: 'fedora', dockerfile: 'Dockerfile_fedora'}
- {container: 'manjaro', dockerfile: 'Dockerfile_manjaro'}
- {container: 'redhat', dockerfile: 'Dockerfile_redhat'}
- {container: 'ubuntu', dockerfile: 'Dockerfile'}
- {container: 'opensuse', dockerfile: 'Dockerfile_opensuse'}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Extract tag name
run: |
if [[ "${{ github.event_name }}" == "release" ]]; then
echo "NODEBUILDER_VERSION=${GITHUB_REF#refs/tags/}" >> "${GITHUB_ENV}"
else
echo "NODEBUILDER_VERSION=$(git describe --tags --abbrev=0)" >> "${GITHUB_ENV}"
fi
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: docker/${{ matrix.config.dockerfile }}
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ matrix.config.container }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ matrix.config.container }}-${{ env.NODEBUILDER_VERSION }}
${{ matrix.config.container == 'ubuntu' && '${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest' || '' }}
${{ matrix.config.container == 'ubuntu' && '${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.NODEBUILDER_VERSION }}' || '' }}