Skip to content

Build and Push Container #1487

Build and Push Container

Build and Push Container #1487

Workflow file for this run

---
name: Build and Push Container
on:
pull_request:
push:
branches:
- main
schedule:
- cron: '25 10 * * *'
workflow_dispatch:
inputs:
debug:
type: boolean
required: false
default: 'false'
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
# Test the image builds and works correctly.
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Test building image.
run: docker build -t docker-test .
- name: Run the built image.
run: docker run --name test-container -d --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro docker-test
# If on master branch, build and release image.
release:
name: Release
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v3
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push image.
uses: docker/build-push-action@v3
with:
context: ./
file: Dockerfile
platforms: linux/amd64
push: true
tags: |
buluma/github-action-molecule:latest, buluma/github-action-molecule:5.0.9
ghcr.io/${{ github.repository }}:latest, ghcr.io/${{ github.repository }}:5.0.9