Skip to content

Create workflow to build image and publish it into Docker Hub #1

Create workflow to build image and publish it into Docker Hub

Create workflow to build image and publish it into Docker Hub #1

Workflow file for this run

name: Docker Image CI
on:
push:
branches:
- main
pull_request:
branches:
- main
permissions:
id-token: write
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Install Cosign
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- id: docker_meta
uses: docker/metadata-action@v4.4.0
with:
images: ${{ secrets.DOCKER_HUB_USERNAME }}/btc
tags: type=sha,format=long
- name: Build and push Docker image
id: build-and-push@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.docker_meta.output.tags }}
- name: Sign the images with GitHub OIDC Token
env:
DIGEST: ${{ steps.build-and-push.outputs.digest }}
TAGS: ${{ steps.docker_meta.outputs.tags }}
run: |
images=""
for tag in ${TAGS}; do
images+="${tag}@${DIGEST} "
done
cosign sign --yes ${images}
- name: Logout from Docker Hub
run: docker logout