This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
133 lines (117 loc) · 3.98 KB
/
publish-docker-images.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
# This workflow publishes docker images base on .ci/.docker-images.yml`.
# See docs/INTERNAL_DOCKER_IMAGES.md for further information.
name: publish-docker-images
on:
workflow_dispatch:
schedule:
- cron: '0 3 * * 1-5'
env:
DOCKER_BUILDKIT: 1
REGISTRY: docker.elastic.co
PREFIX: observability-ci
permissions:
contents: read
jobs:
create-matrix:
name: Create Matrix
runs-on: ubuntu-latest
outputs:
include: ${{ steps.create-matrix.outputs.include }}
steps:
- uses: actions/checkout@v4
- run: pip install pyyaml
- name: Create Matrix
id: create-matrix
shell: python
run: |
import os
import json
import yaml
images = []
with open(".ci/.docker-images.yml", "r") as stream:
images.extend(yaml.safe_load(stream)['images'])
images_json = json.dumps(images)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f'include={images_json}', file=f)
build-test-push:
name: "${{ matrix.name }}:${{ matrix.tag || 'latest' }}"
runs-on: ubuntu-latest
needs: create-matrix
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.create-matrix.outputs.include )}}
defaults:
run:
working-directory: ${{ matrix.working_directory || '.' }}
steps:
- name: Get token
id: get_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
with:
app_id: ${{ secrets.ELASTIC_OBSERVABILITY_APP_ID }}
private_key: ${{ secrets.ELASTIC_OBSERVABILITY_APP_PEM }}
permissions: >-
{
"contents": "read",
}
- uses: actions/checkout@v4
with:
repository: ${{ matrix.repository }}
token: ${{ steps.get_token.outputs.token }}
ref: ${{ matrix.branch }}
- name: Login to docker.elastic.co
uses: docker/login-action@v3
with:
registry: ${{ secrets.ELASTIC_DOCKER_REGISTRY }}
username: ${{ secrets.ELASTIC_DOCKER_USERNAME }}
password: ${{ secrets.ELASTIC_DOCKER_PASSWORD }}
- name: Login to dockerhub
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKERHUB_REGISTRY }}
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Prepare
if: ${{ matrix.prepare_script }}
run: ${{ matrix.prepare_script }}
- name: Generate Image Name
id: generate-image-name
run: echo "image_name=${{ env.REGISTRY }}/${{ env.PREFIX }}/${{ env.NAME }}:${{ env.TAG }}" >> "$GITHUB_OUTPUT"
env:
NAME: ${{ matrix.name }}
TAG: ${{ matrix.tag || 'latest' }}
- name: Build
run: |
echo "DEBUG: ${{ matrix.build_script }}"
if [ -z "${{ matrix.build_script}}" ]; then
echo "DEBUG: run docker build"
docker build \
--cache-from=${{ steps.generate-image-name.outputs.image_name }} \
${{ matrix.build_opts }} \
-t ${{ steps.generate-image-name.outputs.image_name }} \
.
else
echo "DEBUG: run build_script"
bash -c "${{ matrix.build_script }}"
fi
env:
NAME: ${{ matrix.name }}
TAG: ${{ matrix.tag || 'latest' }}
- name: Test
if: ${{ matrix.test_script }}
run: ${{ matrix.test_script }}
- name: Push
if: ${{ matrix.push != 'false' }}
run: |
if [ -z "${{ matrix.push_script }}" ]; then
docker push ${{ steps.generate-image-name.outputs.image_name }}
else
bash -c "${{ matrix.push_script }}"
fi
- if: failure() && github.event_name == 'schedule'
uses: elastic/oblt-actions/slack/notify-result@v1
with:
bot-token: ${{ secrets.SLACK_BOT_TOKEN }}
channel-id: "#observablt-bots"