Skip to content

Commit

Permalink
github mac workers doesn't support docker, try to build with qemu ins…
Browse files Browse the repository at this point in the history
…tead, and fixed a few bugs
  • Loading branch information
haakonnessjoen committed Aug 4, 2024
1 parent b5ece76 commit 5495add
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 88 deletions.
41 changes: 41 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.DS_Store
.idea
*~
ABOUT-NLS
ChangeLog
autom4te.cache
autoscan.log
autoscan-*.log
aclocal.m4
compile
src/config.h.in
depcomp
install-sh
missing
src/stamp-h1
**/*.o
.deps
m4/*.m4
Makefile
Makefile.in
config.guess
config.rpath
config.sub
config.log
config.status
configure
configure.scan
po/Makevars.template
po/POTFILES
po/*.gmo
po/*.mo
po/*.pot
po/remove-potcdate.sed
src/macping
src/mactelnet
src/mactelnetd
src/mndp
src/.deps/
src/config.h
doc/mactelnetd.1
Dockerfile
83 changes: 9 additions & 74 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,12 @@ jobs:
attestations: write
id-token: write
name: Configure and Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false

matrix:
os: [ubuntu-latest, macos-14]
runs-on: ubuntu-latest

steps:
- name: Prepare variables
id: vars
run: |
os=${{ matrix.os }}
platform="$(test \"$os\" = \"ubuntu-latest\" && echo linux/amd64 || echo linux/arm64)"
echo "platform=${platform}" >> $GITHUB_OUTPUT
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand All @@ -47,65 +37,10 @@ jobs:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push by digest
id: build
uses: docker/build-push-action@v6
- name: Build and push
uses: docker/build-push-action@v5
with:
platforms: ${{ steps.vars.outputs.platform }}
labels: ${{ steps.meta.outputs.labels }},
outputs: type=image,name=${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true

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

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.IMAGE_NAME }}

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.version }},latest
17 changes: 11 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
FROM alpine:3.19 AS builder
FROM debian:bookworm AS builder

# Install build dependencies
RUN apk add --no-cache diffutils build-base automake autoconf git gettext gettext-dev linux-headers openssl-dev
RUN apt-get update && apt-get -y install \
gettext autoconf automake libtool autopoint \
libssl-dev git libbsd-dev build-essential && \
apt-get clean && rm -rf /tmp/* /var/tmp/*

# Copy everything to /src
RUN mkdir /src
WORKDIR /src
ADD . /src/

# Build
ENV CFLAGS="-D_GNU_SOURCE"
RUN ./autogen.sh --prefix=/build
RUN ./autogen.sh --prefix=/build --sysconfdir=/config
RUN make all install

##
FROM alpine:3.19
FROM debian:bookworm-slim

# Install runtime dependencies
RUN apk add --no-cache gettext-libs openssl-dev
RUN apt-get update && apt-get -y install gettext \
libbsd0 openssl man-db && apt-get clean && \
rm -rf /tmp/* /var/tmp/*

# Copy build artifacts
COPY --from=builder /build/ /usr/
COPY --from=builder /config /config

CMD ["/usr/bin/mactelnet"]
2 changes: 1 addition & 1 deletion config/mactelnetd.users
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# If you need to add a new user, use the -a option in mactelnetd.
#
# Format:
#username:hash:salt or username:password
#username:hash:salt or username:password
4 changes: 0 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ mactelnetd_SOURCES = config.h mactelnetd.c protocol.c protocol.h interfaces.c in
mactelnetd_CFLAGS = -DFROM_MACTELNETD -DUSERSFILE='"$(sysconfdir)/mactelnetd.users"'
mactelnetd_LDADD = $(CRYPTO_LIBS) $(COREFOUNDATION_LIBS) $(SYSTEMCONFIGURATION_LIBS)

savepass_SOURCES = config.h savepass.c mtwei.c mtwei.h users.c users.h extra.h utlist.h
savepass_CFLAGS = -DUSERSFILE='"$(sysconfdir)/mactelnetd.users"'
savepass_LDADD = $(CRYPTO_LIBS)

mndp_SOURCES = config.h mndp.c mndp.h protocol.c protocol.h extra.h

macping_SOURCES = config.h macping.c interfaces.c interfaces.h protocol.c protocol.h extra.h utlist.h
Expand Down
6 changes: 3 additions & 3 deletions src/mactelnetd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,9 +1188,9 @@ int main(int argc, char **argv) {
textdomain(PACKAGE);

#if !defined(__APPLE__)
while ((c = getopt(argc, argv, "fnovh?")) != -1) {
while ((c = getopt(argc, argv, "fnovh?lau:p:d:")) != -1) {
#else
while ((c = getopt(argc, argv, "novhlau:p:d:")) != -1) {
while ((c = getopt(argc, argv, "novh?lau:p:d:")) != -1) {
#endif
switch (c) {
case 'f':
Expand Down Expand Up @@ -1239,7 +1239,7 @@ int main(int argc, char **argv) {

if (print_help) {
print_version();
fprintf(stderr, _("Usage: %s [-fnoh]|-a [-u <user>|-p <password>]|[-d <user>]\n"), argv[0]);
fprintf(stderr, _("Usage: %s [-fnovh]|-l|-a [-u <user>|-p <password>]|[-d <user>]\n"), argv[0]);

if (print_help) {
#if !defined(__APPLE__)
Expand Down
7 changes: 7 additions & 0 deletions src/mndp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@

char *ether_ntoa_z(const struct ether_addr *addr);

static void sig_term(int signo) {
exit(0);
}

/* This file is also used for the -l option in mactelnet */
#ifndef FROM_MACTELNET

Expand All @@ -66,6 +70,9 @@ int mndp(int timeout, int batch_mode) {
mt_direction_fromserver = 0;
signal(SIGALRM, sig_alarm);
#endif
// Add support for ctrl+c inside docker containers
signal(SIGTERM, sig_term);
signal(SIGINT, sig_term);

setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
Expand Down

0 comments on commit 5495add

Please sign in to comment.