Skip to content

Commit

Permalink
Add Docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsproul committed Jun 17, 2024
1 parent cfc8ea2 commit a4255dc
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: docker

on:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

jobs:
build-docker-single-arch:
name: build-docker-${{ matrix.cpu_arch }}
strategy:
matrix:
cpu_arch: [aarch64, x86_64]
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable
- name: Dockerhub login
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
- name: Cross build binaries
run: |
cargo install cross
make build-${{ matrix.arch }}
- name: Make bin dir
run: mkdir ./bin

- name: Move cross-built binary into Docker scope
run: mv ./target/${{ matrix.cpu_arch }}-unknown-linux-gnu/release/eleel ./bin

- name: Map aarch64 to arm64 short arch
if: startsWith(matrix.cpu_arch, 'aarch64')
run: echo "SHORT_ARCH=arm64" >> $GITHUB_ENV

- name: Map x86_64 to amd64 short arch
if: startsWith(matrix.cpu_arch, 'x86_64')
run: echo "SHORT_ARCH=amd64" >> $GITHUB_ENV

- name: Install QEMU
run: sudo apt-get update && sudo apt-get install -y qemu-user-static

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

- name: Build and push
uses: docker/build-push-action@v5
with:
file: ./Dockerfile.cross
context: .
platforms: linux/${{ env.SHORT_ARCH }}
push: true
tags: |
${{ github.repository_owner }}/eleel:latest-${{ env.SHORT_ARCH }}
build-docker-multiarch:
name: build-docker-eleel-multiarch
runs-on: ubuntu-22.04
needs: [build-docker-single-arch]
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Dockerhub login
run: |
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
- name: Create and push multiarch manifests
run: |
docker buildx imagetools create -t ${{ github.repository_owner}}/eleel:latest \
${{ github.repository_owner}}/eleel:latest-arm64 \
${{ github.repository_owner}}/eleel:latest-amd64;
10 changes: 10 additions & 0 deletions Dockerfile.cross
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This image is meant to enable cross-architecture builds.
# It assumes the eleel binary has already been
# compiled for `$TARGETPLATFORM` and moved to `./bin`.
FROM --platform=$TARGETPLATFORM ubuntu:24.04
RUN apt-get update && apt-get install -y --no-install-recommends \
libssl-dev \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
COPY ./bin/lighthouse /usr/local/bin/lighthouse
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build-x86_64:
cross build --bin eleel --target x86_64-unknown-linux-gnu --profile release --locked

build-x86_64:
cross build --bin eleel --target x86_64-unknown-linux-gnu --profile release --locked

0 comments on commit a4255dc

Please sign in to comment.