Skip to content

Push Docker image

Push Docker image #112

---
# 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: slc9-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-22.04
# 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
# Some images are too large and we run out of disk space, so try to free some
- name: Free disk space
run: |
# https://github.com/jlumbroso/free-disk-space
set -ex
sudo rm -rf /usr/local/lib/android || true
sudo rm -rf /usr/share/dotnet || true
sudo rm -rf /opt/ghc || true
sudo rm -rf /usr/local/.ghcup || true
sudo docker image prune --all --force || true
- name: Install prerequisites
run: |
sudo apt update -y
sudo apt install -y software-properties-common
sudo add-apt-repository universe
# containerd.io conflicts with docker.io
sudo apt-get remove containerd.io
sudo apt install -y docker.io
# The packer provided by Ubuntu repos is ancient
curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install packer
packer plugins install github.com/hashicorp/docker
env:
DEBIAN_FRONTEND: noninteractive
- name: Log in to Docker repo
run: |
docker login registry.cern.ch -u '${{ secrets.CERN_REGISTRY_USER }}' --password-stdin <<\EOF
${{ secrets.CERN_REGISTRY_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