This repository has been archived by the owner on Oct 28, 2024. It is now read-only.
publish-docker-images #684
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
# 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" |