From 4152335a49128df86c49497eece7fe20420b5e60 Mon Sep 17 00:00:00 2001 From: Roman Dodin Date: Wed, 27 Sep 2023 16:06:13 +0200 Subject: [PATCH] Added multi platform build (#2) * added multi platform build * added test on push * remove tty alloc * fix local testing with act --- .github/workflows/build-release.yml | 67 ++++++++++++++++------------ .github/workflows/event-log.yml.bak | 18 -------- .github/workflows/release-event.json | 5 ++- README.md | 15 ++++++- run.sh | 2 +- 5 files changed, 55 insertions(+), 52 deletions(-) delete mode 100644 .github/workflows/event-log.yml.bak diff --git a/.github/workflows/build-release.yml b/.github/workflows/build-release.yml index fd30308..ad3f257 100644 --- a/.github/workflows/build-release.yml +++ b/.github/workflows/build-release.yml @@ -3,6 +3,7 @@ name: Container build release: types: - published + push: jobs: build: @@ -15,14 +16,20 @@ jobs: - python:3.10-slim steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: | + echo "$GITHUB_CONTEXT" + - name: Checkout uses: actions/checkout@v3 - # - name: Set up QEMU - # uses: docker/setup-qemu-action@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - # - name: Set up Docker Buildx - # uses: docker/setup-buildx-action@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - name: Process base image id: base-image @@ -53,31 +60,33 @@ jobs: - name: Test run: | - docker run --rm -it app:latest ansible --version + docker run --rm app:latest ansible --version - # - name: Login to GitHub Container Registry - # if: github.event_name == 'release' - # uses: docker/login-action@v2 - # with: - # registry: ghcr.io - # username: ${{ github.repository_owner }} - # password: ${{ secrets.GITHUB_TOKEN }} + - name: Login to GitHub Container Registry + if: github.event_name == 'release' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - # - name: Process ansible core version - # id: ansible-core-version - # run: | - # TAG_NAME=${{ github.event.release.tag_name }} - # TAG_NAME=${TAG_NAME#v} # remove the leading v - # echo "Tag name without leading v: $TAG_NAME" - # echo "::set-output name=ansible-core-version::$TAG_NAME" + - name: Process ansible core version + if: github.event_name == 'release' + id: ansible-core-version + run: | + TAG_NAME=${{ github.event.release.tag_name }} + TAG_NAME=${TAG_NAME#v} # remove the leading v + echo "Tag name without leading v: $TAG_NAME" + echo "::set-output name=ansible-core-version::$TAG_NAME" - # - name: Build and Push - # if: github.event_name == 'release' - # uses: docker/build-push-action@v4 - # with: - # context: . - # push: true - # build-args: | - # BASE_IMAGE=${{ matrix.py-base-image }} - # ANSIBLE_CORE_VERSION=${{ steps.ansible-core-version.outputs.ansible-core-version }} - # tags: ${{ steps.meta.outputs.tags }} + - name: Build and Push + if: github.event_name == 'release' && !github.event.act + uses: docker/build-push-action@v4 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + build-args: | + BASE_IMAGE=${{ matrix.py-base-image }} + ANSIBLE_CORE_VERSION=${{ steps.ansible-core-version.outputs.ansible-core-version }} + tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/event-log.yml.bak b/.github/workflows/event-log.yml.bak deleted file mode 100644 index 099ec1f..0000000 --- a/.github/workflows/event-log.yml.bak +++ /dev/null @@ -1,18 +0,0 @@ -# change this to the event type you want to get the data for -"on": - release: - types: - - "created" - push: - -# enable this workflow to dump the full event json to the log -jobs: - printJob: - name: Print event - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: | - echo "$GITHUB_CONTEXT" diff --git a/.github/workflows/release-event.json b/.github/workflows/release-event.json index 8ab07fb..ffc129e 100644 --- a/.github/workflows/release-event.json +++ b/.github/workflows/release-event.json @@ -1,8 +1,9 @@ { + "act": true, "action": "created", - "ref": "refs/tags/v0.0.0-test2", + "ref": "refs/tags/v2.12.0", "sha": "b7e12928f13caf61af40d3e8788649a1a8f24c22", "release": { - "tag_name": "v0.0.0-test2" + "tag_name": "v2.12.0" } } \ No newline at end of file diff --git a/README.md b/README.md index b502a98..49f8b4e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,13 @@ -# ansible -ansible container image +# Ansible-core container image + +This repository contains the source for building ansible-core container image using the following python versions: + +* pypy (slim) +* python (slim) + +The image is tagged with the python backend/version and a matching ansible-core version, e.g.: + +* `ghcr.io/srl-labs/ansible-core/pypy3.10:2.12.0` for pypy3.10 backend and ansible-core 2.12.0 +* `ghcr.io/srl-labs/ansible-core/py3.10:2.12.0` for python3.10 backend and ansible-core 2.12.0 + +Images are built for linux/amd64 and linux/arm64 architectures. diff --git a/run.sh b/run.sh index 042ab5a..1c0354d 100755 --- a/run.sh +++ b/run.sh @@ -67,7 +67,7 @@ function build { # testing release-triggered workflow function test-act-release { - gh act -W '.github/workflows/build-release.yml' -e .github/workflows/release-event.json -s GITHUB_TOKEN="$(gh auth token)" --matrix py-base-image:pypy:3.10-slim + gh act release -W '.github/workflows/build-release.yml' -e .github/workflows/release-event.json -s GITHUB_TOKEN="$(gh auth token)" --matrix py-base-image:pypy:3.10-slim } # -----------------------------------------------------------------------------