-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathaction.yml
117 lines (116 loc) · 4.26 KB
/
action.yml
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# Copyright (c) 2024 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: Build Container Group
description: Given the inputs found below, build all containers found in a docker-compose.yaml file for a given configuration
author: [email protected]
inputs:
group_dir:
description: Directory with docker-compose.yaml to build
required: true
type: string
env_overrides:
description: Bash Env Variable Overrides in `KEY=VAL && KEY2=VAL2` format
required: false
type: string
registry:
description: Container Registry URL
required: false
default: 'intel'
type: string
repo:
description: Container Project Repository
required: false
default: 'ai-containers'
type: string
no-push:
description: Do not push to Registry
required: false
default: false
type: boolean
no-start:
description: Do not start containers after building them
required: false
default: false
type: boolean
outputs:
container-group:
description: "Container Group"
value: ${{ steps.container-output.outputs.group }}
runs:
using: composite
steps:
- name: Generate Project Number
shell: bash
run: echo "project-number=$(shuf -i 0-10000 -n1)" >> $GITHUB_ENV
- name: Build Containers
shell: bash
if: ${{ !fromJson(inputs.no-start) }}
run: |
REGISTRY=${{ inputs.registry }} \
REPO=${{ inputs.repo }} \
COMPOSE_PROJECT_NAME=${{ env.project-number }} \
${{ inputs.env_overrides }} docker compose -p ${{ env.project-number }} up --build --force-recreate --always-recreate-deps
working-directory: ${{ inputs.group_dir }}
- name: Build Containers
shell: bash
if: ${{ fromJson(inputs.no-start) }}
run: |
REGISTRY=${{ inputs.registry }} \
REPO=${{ inputs.repo }} \
COMPOSE_PROJECT_NAME=${{ env.project-number }} \
${{ inputs.env_overrides }} docker compose -p ${{ env.project-number }} up --build --force-recreate --always-recreate-deps --no-start
working-directory: ${{ inputs.group_dir }}
- name: Print Containers
id: container-output
shell: bash
run: |
mkdir matrix
images=$(REGISTRY=${{ inputs.registry }} \
REPO=${{ inputs.repo }} \
COMPOSE_PROJECT_NAME=${{ env.project-number }} \
${{ inputs.env_overrides }} docker compose -p ${{ env.project-number }} images --format json)
for image in $(echo $images | jq -r --arg registry "$REGISTRY" '.[] | select(.Repository | contains($registry)) | .Tag'); do
echo "$image" > matrix/$image.txt
done
echo "group=${{ inputs.group_dir }}" | tr '/' '_' >> $GITHUB_OUTPUT
working-directory: ${{ inputs.group_dir }}
- uses: actions/upload-artifact@v4
with:
name: ${{ env.project-number }}-${{ steps.container-output.outputs.group }}
path: ${{ inputs.group_dir }}/matrix/*
retention-days: 1
overwrite: true
- name: Push Containers
shell: bash
if: ${{ !fromJson(inputs.no-push) }}
run: |
REGISTRY=${{ inputs.registry }} \
REPO=${{ inputs.repo }} \
COMPOSE_PROJECT_NAME=${{ env.project-number }} \
${{ inputs.env_overrides }} docker compose -p ${{ env.project-number }} push
working-directory: ${{ inputs.group_dir }}
- name: Un-Tag Containers
if: ${{ always() }}
shell: bash
run: |
REGISTRY=${{ inputs.registry }} \
REPO=${{ inputs.repo }} \
COMPOSE_PROJECT_NAME=${{ env.project-number }} \
${{ inputs.env_overrides }} docker compose -p ${{ env.project-number }} down --rmi all
working-directory: ${{ inputs.group_dir }}
- name: Remove Containers
if: ${{ always() }}
shell: bash
run: docker system prune --force