Skip to content

Commit

Permalink
add - multi architecture builds x64 & arm64
Browse files Browse the repository at this point in the history
* add - multi architecture builds x64 & arm64
  • Loading branch information
chaddyc authored Dec 15, 2024
1 parent fa82817 commit e88d1c0
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 28 deletions.
47 changes: 19 additions & 28 deletions .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
docker-build:
if: ${{ github.ref == 'refs/heads/main' && contains('["chaddyc"]', github.actor) }}
# if: ${{ github.ref == 'refs/heads/main' && contains('["chaddyc"]', github.actor) }}
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ github.token }}
Expand All @@ -28,41 +28,32 @@ jobs:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push ubuntu 22.04 amd64
- name: Build and push ubuntu 22.04
uses: docker/build-push-action@v6
with:
context: amd64.Dockerfile
platforms: linux/amd64
build-arg: UBUNTU_VERSION=22.04-amd64
file: Dockerfile
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=22.04
push: true
tags: chaddyc/${{ github.event.repository.name }}:22.04-amd64
tags: chaddyc/${{ github.event.repository.name }}:22.04

- name: Build and push ubuntu 22.04 arm64
- name: Build and push ubuntu 24.04
uses: docker/build-push-action@v6
with:
context: arm64.Dockerfile
platforms: linux/arm64
build-arg: UBUNTU_VERSION=22.04-ARM64
context: .
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=24.04
push: true
tags: chaddyc/${{ github.event.repository.name }}:22.04

# - name: Build and push ubuntu 24.04
# uses: docker/build-push-action@v6
# with:
# context: .
# platforms: linux/amd64,linux/arm64
# build-arg: UBUNTU_VERSION=24.04
# push: true
# tags: chaddyc/${{ github.event.repository.name }}:24.04
tags: chaddyc/${{ github.event.repository.name }}:24.04

# - name: Build and push ubuntu latest
# uses: docker/build-push-action@v6
# with:
# context: .
# platforms: linux/amd64,linux/arm64
# build-arg: UBUNTU_VERSION=latest
# push: true
# tags: chaddyc/${{ github.event.repository.name }}:latest
- name: Build and push ubuntu latest
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=latest
push: true
tags: chaddyc/${{ github.event.repository.name }}:latest

- name: Update docker readme description
uses: peter-evans/dockerhub-description@v3
Expand Down
64 changes: 64 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Docker Test

on:
pull_request:
branches:
- main


jobs:
docker-build:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ github.token }}
REPO: ${{ github.event.repository.name }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up QEM
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push ubuntu 22.04
uses: docker/build-push-action@v6
with:
file: Dockerfile
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=22.04
push: false
tags: chaddyc/${{ github.event.repository.name }}:22.04

- name: Build and push ubuntu 24.04
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=24.04
push: false
tags: chaddyc/${{ github.event.repository.name }}:24.04

- name: Build and push ubuntu latest
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
build-arg: UBUNTU_VERSION=latest
push: false
tags: chaddyc/${{ github.event.repository.name }}:latest

- name: Update docker readme description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: chaddyc/${{ github.event.repository.name }}

51 changes: 51 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
ARG UBUNTU_VERSION=20.04
FROM ubuntu:${UBUNTU_VERSION}
LABEL org.opencontainers.image.authors="https://github.com/chaddyc"

ARG TARGETARCH
RUN echo "Detected architecture: ${TARGETARCH}"

ENV RUNNER_ARCH=${RUNNER_ARCH}

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$RUNNER_ARCH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$RUNNER_ARCH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

Check warning on line 8 in Dockerfile

View workflow job for this annotation

GitHub Actions / docker-build

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$RUNNER_ARCH' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
curl \
jq \
git \
tar \
sudo \
software-properties-common && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

WORKDIR /runner

RUN LATEST_RUNNER_VERSION=$(curl -s https://api.github.com/repos/actions/runner/releases/latest | jq -r .tag_name) && \
RUNNER_VERSION_NUMBER=$(echo "$LATEST_RUNNER_VERSION" | sed 's/^v//') && \
if [ "${TARGETARCH}" = "amd64" ]; then \
export RUNNER_ARCH="x64"; \
elif [ "${TARGETARCH}" = "arm64" ]; then \
export RUNNER_ARCH="arm64"; \
else \
echo "Unsupported architecture: ${TARGETARCH}"; exit 1; \
fi && \
echo "Downloading https://github.com/actions/runner/releases/download/$LATEST_RUNNER_VERSION/actions-runner-linux-$RUNNER_ARCH-$RUNNER_VERSION_NUMBER.tar.gz" && \
curl -L -o actions-runner.tar.gz https://github.com/actions/runner/releases/download/$LATEST_RUNNER_VERSION/actions-runner-linux-$RUNNER_ARCH-$RUNNER_VERSION_NUMBER.tar.gz && \
tar xzf actions-runner.tar.gz && \
rm -f actions-runner.tar.gz

RUN ./bin/installdependencies.sh

RUN useradd -m -s /bin/bash runner && \
echo "runner ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

RUN chown -R runner:runner /runner

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

USER runner
WORKDIR /runner

ENTRYPOINT ["/entrypoint.sh"]
File renamed without changes.
File renamed without changes.

0 comments on commit e88d1c0

Please sign in to comment.