blob: 8eb7b215037bcb5906921c517bc5ac2dc0f7d2da [file]
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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 Image
on:
push:
tags:
- '*.*.*.*'
branches-ignore:
- '**'
workflow_dispatch:
jobs:
image:
name: Build OpenServerless Devcontainer Image
runs-on: ubuntu-22.04
permissions:
contents: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v7
with:
submodules: recursive
# full history and tags: "task tag" replaces the existing tags
# and "git describe" needs them to be present
fetch-depth: 0
- name: Setup
run: |
sudo sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin
# Manual run: create a new snapshot tag on the current HEAD and push it.
# The push of the tag does not start another run (GITHUB_TOKEN pushes do
# not trigger workflows), so this same run goes on and builds it.
- name: Tag HEAD (manual run)
if: ${{ github.event_name == 'workflow_dispatch' }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
task tag
task ci
echo "IMG_TAG=$(git describe --tags --abbrev=0)" >> "$GITHUB_ENV"
- name: Assign TAG from push
if: ${{ github.event_name == 'push' }}
run: echo "IMG_TAG=${{ github.ref_name }}" >> "$GITHUB_ENV"
- name: Generate .env
run: |
OWNER=$(echo "${{ github.repository_owner }}" | tr '[:upper:]' '[:lower:]')
if [ "$OWNER" = "apache" ]; then
IMAGE=$(awk -F= '/ARG DEVCONTAINER_IMAGE_DEFAULT=/ { print $2 ; exit }' Dockerfile)
else
IMAGE="ghcr.io/$OWNER/openserverless-devcontainer"
fi
echo "GITHUB_USER=$OWNER" > .env
echo "MY_DEVCONTAINER_IMAGE=$IMAGE" >> .env
cat .env
- name: Select registry
env:
DOCKERHUB_REGISTRY: ${{ secrets.DOCKERHUB_REGISTRY }}
run: |
if [ -n "$DOCKERHUB_REGISTRY" ]; then
REGISTRY="$DOCKERHUB_REGISTRY"
elif [ "${{ github.repository_owner }}" = "apache" ]; then
REGISTRY="docker.io"
else
REGISTRY="ghcr.io"
fi
echo "REGISTRY=$REGISTRY" >> "$GITHUB_ENV"
- name: Select registry credentials
run: |
if [ "${REGISTRY%%/*}" = "ghcr.io" ]; then
echo "REGISTRY_USER=${{ github.actor }}" >> "$GITHUB_ENV"
echo "REGISTRY_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> "$GITHUB_ENV"
else
echo "REGISTRY_USER=${{ secrets.DOCKERHUB_USER }}" >> "$GITHUB_ENV"
echo "REGISTRY_TOKEN=${{ secrets.DOCKERHUB_TOKEN }}" >> "$GITHUB_ENV"
fi
- name: Registry login
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # v4.4.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4.2.0
with:
image: tonistiigi/binfmt:qemu-v7.0.0-28
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0
- name: Image
run: task buildx PUSH=1 DEVCONTAINER_TAG=$IMG_TAG