Skip to content

Push Docker image

Push Docker image #101

---
# Build and push the selected docker image from a packer config.
name: Push Docker image
# Controls when the action will run: manual trigger with a parameter
'on':
workflow_dispatch:
inputs:
image-name:
description: Docker image to build
required: true
default: slc8-builder
permissions:
contents: read
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# GitHub seems to install an odd version of docker on the host, so run in a
# container and only connect to the host's docker daemon.
container:
image: ubuntu:22.04
volumes:
# Connect to host's docker daemon so we don't run docker inside docker.
- /var/run/docker.sock:/var/run/docker.sock
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
apt update -y
apt install -y software-properties-common
add-apt-repository universe
apt install -y docker.io packer
# packer plugins install github.com/hashicorp/docker
env:
DEBIAN_FRONTEND: noninteractive
- name: Log in to Docker repos
run: |
docker login registry.cern.ch -u '${{ secrets.CERN_REGISTRY_USER }}' --password-stdin <<\EOF
${{ secrets.CERN_REGISTRY_PASSWORD }}
EOF
docker login docker.io -u '${{ secrets.DOCKERHUB_USER }}' --password-stdin <<\EOF
${{ secrets.DOCKERHUB_PASSWORD }}
EOF
- name: Build and push docker image
run: |
if ! cd "$GITHUB_WORKSPACE/${{ github.event.inputs.image-name }}"; then
echo 'error: requested docker image not defined in this repo' >&2
exit 1
fi
packer validate packer.json
packer build packer.json