Recognize "!" flag in CTL_ON_{CREATE|START} to ignore failing commands #48
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
name: Tests | |
on: | |
push: | |
paths: | |
- '.github/workflows/tests.yml' | |
- 'ecs/**' | |
- 'mix/**' | |
pull_request: | |
paths: | |
- '.github/workflows/tests.yml' | |
- 'ecs/**' | |
- 'mix/**' | |
env: | |
REGISTRY: ghcr.io | |
REGISTRY_LOCAL: localhost:5000 | |
MIX_IMAGE_NAME: ${{ github.repository_owner }}/mix | |
ECS_IMAGE_NAME: ${{ github.repository_owner }}/ecs | |
jobs: | |
build: | |
name: Build | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: true | |
max-parallel: 1 | |
permissions: | |
packages: write | |
services: | |
registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Log in to the Container registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get git describe | |
id: gitdescribe | |
run: echo "ver=$(git describe --exact-match 2>/dev/null || echo latest)" >> $GITHUB_OUTPUT | |
- name: Extract mix metadata (tags, labels) for Docker | |
id: mixmeta | |
if: github.ref_type == 'tag' | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.MIX_IMAGE_NAME }} | |
labels: | | |
org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }} | |
org.opencontainers.image.licenses=GPL-2.0 | |
org.opencontainers.image.vendor=ProcessOne | |
- name: Extract ecs metadata (tags, labels) for Docker | |
id: ecsmeta | |
if: github.ref_type == 'tag' | |
uses: docker/metadata-action@v4 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.ECS_IMAGE_NAME }} | |
labels: | | |
org.opencontainers.image.revision=${{ steps.gitdescribe.outputs.ver }} | |
org.opencontainers.image.licenses=GPL-2.0 | |
org.opencontainers.image.vendor=ProcessOne | |
- name: Prepare local tags | |
id: localreg | |
run: | | |
tag="$(echo ${{ github.ref_name }} | sed -e 's|[/]\+|-|g')" | |
echo "mixlocaltag=${{ env.REGISTRY_LOCAL }}/${{ env.MIX_IMAGE_NAME }}:$tag" >> $GITHUB_OUTPUT | |
echo "ecslocaltag=${{ env.REGISTRY_LOCAL }}/${{ env.ECS_IMAGE_NAME }}:$tag" >> $GITHUB_OUTPUT | |
echo "mixtag=${{ env.REGISTRY }}/${{ env.MIX_IMAGE_NAME }}:$tag" >> $GITHUB_OUTPUT | |
echo "ecstag=${{ env.REGISTRY }}/${{ env.ECS_IMAGE_NAME }}:$tag" >> $GITHUB_OUTPUT | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
with: | |
driver-opts: network=host | |
- name: Build and push local mix image | |
uses: docker/build-push-action@v4 | |
with: | |
build-args: | | |
VERSION=${{ steps.gitdescribe.outputs.ver }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: mix | |
labels: ${{ steps.mixmeta.outputs.labels }} | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ steps.localreg.outputs.mixlocaltag }} | |
${{ steps.mixmeta.outputs.tags }} | |
- name: Prepare ecs Dockerfile | |
run: sed -i 's|ejabberd/mix|${{ steps.localreg.outputs.mixlocaltag }}|g' ecs/Dockerfile | |
- name: Build and push local ecs image | |
uses: docker/build-push-action@v3 | |
with: | |
build-args: | | |
VERSION=${{ steps.gitdescribe.outputs.ver }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: ecs | |
labels: ${{ steps.ecsmeta.outputs.labels }} | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ steps.localreg.outputs.ecslocaltag }} | |
${{ steps.ecsmeta.outputs.tags }} | |
- name: Run ecs image | |
run: | | |
docker images | |
docker run --name ejabberd -d -p 5222:5222 ${{ steps.localreg.outputs.ecslocaltag }} | |
- name: Wait ejabberd started | |
run: | | |
docker exec ejabberd bin/ejabberdctl started | |
- name: Check ecs results | |
if: always() | |
run: | | |
docker ps -s | |
docker logs ejabberd | |
docker logs ejabberd | grep -q "Start accepting TCP connections" || exit 1 | |
docker logs ejabberd | grep -q "error" && exit 1 || exit 0 | |
docker logs ejabberd | grep -q "Error" && exit 1 || exit 0 | |
- name: Save image | |
run: | | |
docker image save ${{ steps.localreg.outputs.ecslocaltag }} --output ejabberd-latest.tar | |
- name: Upload image | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ejabberd-image | |
path: ejabberd-latest.tar | |
- run: | | |
echo "::notice::To get this image, download ejabberd-image.zip, "\ | |
"uncompress it and run: " \ | |
"docker image load -i ejabberd-latest.tar" | |
- name: Build and push mix image to GHCR | |
uses: docker/build-push-action@v4 | |
if: github.ref_type == 'tag' | |
with: | |
build-args: | | |
VERSION=${{ steps.gitdescribe.outputs.ver }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: mix | |
labels: ${{ steps.mixmeta.outputs.labels }} | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ steps.localreg.outputs.mixtag }} | |
${{ steps.mixmeta.outputs.tags }} | |
- name: Build and push ecs image to GHCR | |
uses: docker/build-push-action@v3 | |
if: github.ref_type == 'tag' | |
with: | |
build-args: | | |
VERSION=${{ steps.gitdescribe.outputs.ver }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: ecs | |
labels: ${{ steps.ecsmeta.outputs.labels }} | |
platforms: linux/amd64 | |
push: true | |
tags: | | |
${{ steps.localreg.outputs.ecstag }} | |
${{ steps.ecsmeta.outputs.tags }} |