You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2022/11/02 01:47:07 UTC

[trafficcontrol] branch master updated: arm64 support for Dev CiaB's prebuilt trafficserver image (#7165)

This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 296473132e arm64 support for Dev CiaB's prebuilt trafficserver image (#7165)
296473132e is described below

commit 296473132eea3de458ed7ba2d2dfac4a8ac32fe2
Author: Zach Hoffman <zr...@apache.org>
AuthorDate: Wed Nov 2 01:47:02 2022 +0000

    arm64 support for Dev CiaB's prebuilt trafficserver image (#7165)
    
    * Get ATS_VERSION directly from .env file
    
    * Set default for CONTAINER environment variable for convenience
    
    * Docker buildkit is default now, no need to specify it
    
    * Use v2 of docker/login-action
    
    * Only run if ATS version was changed within the last 4 commits
    
    * Use single quotes when possible
    
    * Use a single variable for image name
    
    * Build trafficserver-alpine image for arm64, too
    
    * Build for amd64 and arm64 in separate jobs
    
    * Combine platforms into a single image in a separate step
    
    * Limit threads used to keep runner responsive enough to pass
    
    * Complete sentence
---
 .github/containers/trafficserver-alpine/.env       |  1 +
 .github/containers/trafficserver-alpine/Dockerfile |  8 +-
 .../trafficserver-alpine/docker-compose.yml        | 20 ++++-
 .../workflows/container-trafficserver-alpine.yml   | 89 +++++++++++++++++++---
 4 files changed, 105 insertions(+), 13 deletions(-)

diff --git a/.github/containers/trafficserver-alpine/.env b/.github/containers/trafficserver-alpine/.env
new file mode 120000
index 0000000000..e72b3932f4
--- /dev/null
+++ b/.github/containers/trafficserver-alpine/.env
@@ -0,0 +1 @@
+../../../.env
\ No newline at end of file
diff --git a/.github/containers/trafficserver-alpine/Dockerfile b/.github/containers/trafficserver-alpine/Dockerfile
index 4788c73f34..9efce0a9b8 100644
--- a/.github/containers/trafficserver-alpine/Dockerfile
+++ b/.github/containers/trafficserver-alpine/Dockerfile
@@ -18,7 +18,7 @@
 FROM alpine:latest AS build-trafficserver
 ARG ATS_VERSION
 ADD https://downloads.apache.org/trafficserver/trafficserver-${ATS_VERSION}.tar.bz2 /tmp/
-RUN set -o errexit -o nounset; \
+RUN set -o errexit -o nounset -o xtrace; \
     cd tmp; \
     dirname=trafficserver-${ATS_VERSION}; \
     tar xf ${dirname}.tar.bz2; \
@@ -42,7 +42,11 @@ RUN set -o errexit -o nounset; \
         --prefix=/ \
         --with-user=ats \
         --with-group=ats; \
-    make -j; \
+    # Not limiting threads makes the GitHub Actions Hosted Agent lose
+    # communication with the server due to memory exhaustion, making the
+    # Action fail.
+    threads=$(( $(nproc) )); \
+    make -j $threads; \
     adduser -D ats; \
     make install DESTDIR=/tmp/built; \
     cd ..; \
diff --git a/.github/containers/trafficserver-alpine/docker-compose.yml b/.github/containers/trafficserver-alpine/docker-compose.yml
index cb5e4d1936..68cd428377 100644
--- a/.github/containers/trafficserver-alpine/docker-compose.yml
+++ b/.github/containers/trafficserver-alpine/docker-compose.yml
@@ -23,5 +23,23 @@ services:
       dockerfile: Dockerfile
       args:
         ATS_VERSION: ${ATS_VERSION}
+      # This docker-compose file is no longer used by the container-trafficserver-alpine.yml
+      # Github Actions workflow and is here in case anyone wants to build it manually, since
+      # the emulated aarch64 GitHub Actions job takes about 3 hours to run.
+      # To build the trafficserver image for only your computer's own platform, run
+      #   docker-compose build
+      #
+      # To build and push a single image including both linux/amd64 and linux/arm64 platforms, run
+      #   # docker/binfmt writes to /proc/sys/fs/binfmt_misc and its effects are cleared on reboot
+      #   docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
+      #   docker buildx create --use
+      #   docker buildx bake --push
+      #
+      # Running `docker buildx bake --load` will not work until docker/roadmap#371 is resolved
+      # because the image would contain more than 1 platform.
+      x-bake:
+        platforms:
+          - linux/amd64
+          - linux/arm64
     # for example, ghcr.io/apache/trafficcontrol/ci/trafficserver-alpine:9.1.2
-    image: ${CONTAINER}:${ATS_VERSION}
+    image: ${CONTAINER:-ghcr.io/apache/trafficcontrol/ci/trafficserver-alpine}:${ATS_VERSION}
diff --git a/.github/workflows/container-trafficserver-alpine.yml b/.github/workflows/container-trafficserver-alpine.yml
index da5c27a603..65ebe20381 100644
--- a/.github/workflows/container-trafficserver-alpine.yml
+++ b/.github/workflows/container-trafficserver-alpine.yml
@@ -18,8 +18,6 @@
 name: Container ghcr.io/apache/trafficcontrol/ci/trafficserver-alpine
 
 env:
-  DOCKER_BUILDKIT: '1'
-  COMPOSE_DOCKER_CLI_BUILD: '1'
   CONTAINER: ghcr.io/${{ github.repository }}/ci/trafficserver-alpine
 
 on:
@@ -38,23 +36,94 @@ on:
 
 jobs:
   build:
+    strategy:
+      matrix:
+        platform: [ 'amd64', 'arm64' ]
     if: ${{ github.repository_owner == 'apache' || github.event_name == 'workflow_dispatch' }}
     runs-on: ubuntu-latest
     steps:
       - name: Checkout repo
         uses: actions/checkout@master
+        with:
+          fetch-depth: 5
+      - name: Check if ATS_VERSION was changed within the last 4 commits
+        run: |2
+          set -o errexit -o nounset -o xtrace
+          ats_line="$(git grep -hn ^ATS_VERSION= .env | cut -d: -f1)"
+          if [[ -z "$ats_line" ]]; then
+            echo "No line containing ATS_VERSION in .env was found"
+            exit 1
+          fi
+          if [[ "$(git log HEAD~4..HEAD -L${ats_line},${ats_line}:.env)" != '' ||
+                "$(git log HEAD~4..HEAD .github/containers/trafficserver-alpine .github/workflows/container-trafficserver-alpine.yml)" != '' ||
+                ${{ github.event_name }} == 'workflow_dispatch' ]]; then
+            echo SHOULD_RUN=1 >> ${{ github.env }}
+          fi
       - name: Load environment
-        run: cp .env "${{ github.env }}"
-      - name: Build ${{ env.CONTAINER }}:${{ env.ATS_VERSION }}
+        if: ${{ env.SHOULD_RUN == '1' }}
+        run: cp .env '${{ github.env }}'
+      - name: Set image name
+        run: echo 'IMAGE_NAME=${{ env.CONTAINER }}:${{ env.ATS_VERSION }}-${{ matrix.platform }}' >> '${{ github.env }}'
+      - name: Install aarch64 emulator
+        if: ${{ env.SHOULD_RUN == '1' && matrix.platform == 'arm64' }}
+        # Updated 2020-02-07 but we're still using docker/binfmt instead of tonistiigi/binfmt@qemu-v6.2.0
+        # because tonistiigi/binfmt@qemu-v6.2.0 fails on building trafficserver after about an hour
+        run: docker run --rm --privileged docker/binfmt:a7996909642ee92942dcd6cff44b9b95f08dad64
+      - name: Make a Docker Buildx builder
+        if: ${{ env.SHOULD_RUN == '1' && matrix.platform == 'arm64' }}
+        run: docker buildx create --name arm64-builder --use
+        # The push can be split into a separate command once docker can store
+        # multi-architecture images (docker/roadmap#371).
+      - name: Build ${{ env.IMAGE_NAME }}
+        if: ${{ env.SHOULD_RUN == '1' }}
         working-directory: .github/containers/trafficserver-alpine
-        run: docker-compose build
+        run: docker buildx build --build-arg ATS_VERSION=${{ env.ATS_VERSION }} --tag ${{ env.IMAGE_NAME }} --platform linux/${{ matrix.platform }} --load .
       - name: docker login ghcr.io
-        uses: docker/login-action@v1
+        if: ${{ env.SHOULD_RUN == '1' }}
+        uses: docker/login-action@v2
         with:
           registry: ghcr.io
           username: ${{ github.repository_owner }}
           password: ${{ secrets.GITHUB_TOKEN }}
-      - name: Push ${{ env.CONTAINER }}:${{ env.ATS_VERSION }}
-        if: ${{ github.event_name != 'pull_request' }}
-        working-directory: .github/containers/trafficserver-alpine
-        run: docker-compose push
+      - name: Push ${{ env.IMAGE_NAME }}
+        if: ${{ env.SHOULD_RUN == '1' && github.event_name != 'pull_request' }}
+        run: docker push ${{ env.IMAGE_NAME }}
+
+  combine-platforms:
+    if: ${{ (github.repository_owner == 'apache' && github.event_name != 'pull_request') || github.event_name == 'workflow_dispatch' }}
+    needs:
+      - build
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout repo
+        uses: actions/checkout@master
+        with:
+          fetch-depth: 5
+      - name: Load environment
+        run: cp .env '${{ github.env }}'
+      - name: Set image name
+        run: |2
+          echo 'IMAGE_NAME=${{ env.CONTAINER }}' >> '${{ github.env }}' &&
+          echo 'FULL_IMAGE_NAME=${{ env.CONTAINER }}:${{ env.ATS_VERSION }}' >> '${{ github.env }}'
+      - name: Create ${{ env.FULL_IMAGE_NAME }} manifest
+        run: |2
+          set -o errexit -o xtrace
+          docker manifest create \
+            ${{ env.FULL_IMAGE_NAME }} \
+            --amend ${{ env.FULL_IMAGE_NAME }}-amd64 \
+            --amend ${{ env.FULL_IMAGE_NAME }}-arm64
+          docker manifest create \
+            ${{ env.IMAGE_NAME }}:latest \
+            --amend ${{ env.FULL_IMAGE_NAME }}-amd64 \
+            --amend ${{ env.FULL_IMAGE_NAME }}-arm64
+      - name: docker login ghcr.io
+        uses: docker/login-action@v2
+        with:
+          registry: ghcr.io
+          username: ${{ github.repository_owner }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Push ${{ env.FULL_IMAGE_NAME }}
+        run: |2
+          set -o errexit -o xtrace
+          docker manifest push --purge ${{ env.FULL_IMAGE_NAME }}
+          docker manifest push --purge ${{ env.IMAGE_NAME }}:latest