-
Notifications
You must be signed in to change notification settings - Fork 26
96 lines (81 loc) · 2.84 KB
/
build-image.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# GitHub Actions Workflow for building and pushing Docker images
# SPDX-License-Identifier: BSD-2-Clause-Patent
# This workflow is intended to be called from another top-level
# workflow. Each set of images (defined in a common Dockerfile)
# should have a matching top-level workflow yaml file.
name: "Build and Push images"
on:
workflow_call:
inputs:
image_name:
type: string
required: true
description: "Name of the image to build (= folder name)"
sub_images:
type: string
required: false
description: "Space-separated list of sub-image names. Can not be empty."
default: "build"
runs_on:
type: string
required: false
description: "The OS used to build the docker image."
default: "ubuntu-latest"
env:
REGISTRY: ghcr.io
REPOSITORY: ${{ github.repository }}
IMAGE_NAME: ${{ inputs.image_name }}
SUB_IMAGES: ${{ inputs.sub_images }}
jobs:
build-and-push-image:
runs-on: ${{ inputs.runs_on }}
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set tag
run: echo "short_sha=$(git rev-parse --short $GITHUB_SHA)" >> $GITHUB_ENV
shell: bash
- name: Build
run: |
cd "${IMAGE_NAME}"
for sub in $SUB_IMAGES; do
IMG=$(tr '[:upper:]' '[:lower:]' <<< "${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}-${sub}")
echo "Building Image: ${IMG}:${short_sha}..."
docker build --target "${sub}" --tag "${IMG}:${short_sha}" -f Dockerfile .
done
docker images
shell: bash
- name: Check (Linux)
if: runner.os == 'Linux'
run: |
# Only check the last sub-image in the list (for now)
sub=${SUB_IMAGES##* }
IMG=$(tr '[:upper:]' '[:lower:]' <<< "${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}-${sub}:${short_sha}")
echo "Launching ${IMG}..."
docker run \
--rm \
--volume "${PWD}":/work \
--workdir /work \
"${IMG}" \
"./.github/workflows/test_build_edk2.sh"
shell: bash
- name: Push
if: ${{ github.ref == 'refs/heads/main' }}
run: |
for sub in $SUB_IMAGES; do
IMG=$(tr '[:upper:]' '[:lower:]' <<< "${REGISTRY}/${REPOSITORY}/${IMAGE_NAME}-${sub}")
echo "Pushing Image: ${IMG}:${short_sha}..."
docker tag "${IMG}:${short_sha}" "${IMG}:latest"
docker push "${IMG}:${short_sha}"
docker push "${IMG}:latest"
done
shell: bash