Skip to content

Container Image

Container Image #101

name: Container Image
on:
workflow_dispatch: {}
workflow_call: {}
schedule:
# every Wednesday morning
- cron: 7 7 * * 3
push:
branches: [ main ]
pull_request:
types: [opened, reopened, synchronize]
concurrency:
group: ci-container-build-${{ github.ref }}-1
cancel-in-progress: true
env:
# Use docker.io for Docker Hub if empty
REGISTRY: quay.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
buildah:
runs-on: ubuntu-latest
steps:
# Allow multi-target builds
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: s390x,ppc64le # arm64
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: redhat-actions/podman-login@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=schedule
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
${{ github.ref_name == 'main' && 'type=raw,value=nightly' || 'type=ref,event=branch' }}
type=ref,event=tag
type=ref,event=pr
# https://github.com/actions/checkout
- uses: actions/checkout@v3
- name: Build image
id: build-image
uses: redhat-actions/buildah-build@v2
with:
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/s390x,linux/ppc64le
labels: ${{ steps.meta.outputs.labels }}
layers: false
oci: true
tls-verify: true
extra-args: |
--squash
--jobs=3
build-args: |
PORTA_IMAGE=quay.io/3scale/porta:nightly
containerfiles: |
Containerfile
- name: Echo Outputs
run: |
echo "Image: ${{ steps.build-image.outputs.image }}"
echo "Tags: ${{ steps.build-image.outputs.tags }}"
echo "Tagged Image: ${{ steps.build-image.outputs.image-with-tag }}"
- name: Check images created
run: buildah images
- name: Smoke test the images
run: |
set -ex
# accessing a mapped port from a container did not work so lets
# create a pod where both - server and client have same localhost
podman pod create > podid
for arch in amd64 s390x ppc64le; do
podman run -d --pod-id-file=podid --name=searchd -u 14:0 ${{ steps.build-image.outputs.image-with-tag }}-linux$arch
sleep 3
podman logs searchd
podman run --pod-id-file=podid --rm --entrypoint "/bin/env" mysql:5.7 -- mysql -h 127.0.0.1 -P 9306 -e "SELECT * FROM account limit 1;"
podman rm -f searchd
done
- name: Push To Container Registry
id: push-to-container-registry
uses: redhat-actions/push-to-registry@v2
if: github.event_name != 'pull_request'
with:
tags: ${{ steps.build-image.outputs.tags }}
- name: Print image url
run: echo "Image pushed to ${{ steps.push-to-container-registry.outputs.registry-paths }}"