Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add native docker images w/ build workflow #316

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Ignore non-build related directories
/.git/
/doc/
/sample/
/vstudio/
/.*/

#prebuilds
/lib/
/out/
/bin/
# Ignore non-build related files
/.dockerignore
/.gitignore
/build_adv.bat
/build_lib.bat
.*
.DS_Store
/*.bat
/changelog.txt
/COPYING.RUNTIME
/Dockerfile
Expand Down
114 changes: 114 additions & 0 deletions .github/workflows/sgdk-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: sgdk-docker

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

on:
workflow_dispatch: # Allows for manual triggering.
pull_request: # Trigger for pull requests.
types: [opened, synchronize, reopened, ready_for_review]
branches:
- master
push: # Trigger when pushed to master.
branches:
- 'master'
paths-ignore:
- 'vstudio/**'
- 'bin/**'
- 'sample/**'
- '**.md'

env:
# TODO: arm64 images are currently disabled because they keep hanging in the
# GitHub Actions environment.
#PLATFORMS: linux/amd64,linux/arm64
PLATFORMS: linux/amd64

jobs:
build:
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

steps:
- name: Checkout
uses: actions/checkout@v4

# TODO: arm64 images are currently disabled because they keep hanging in
# the GitHub Actions environment.
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v3

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

- name: Login to GHCR (only on push event)
if: github.event_name == 'push'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check if GCC Dockerfile has changed
id: changed-files
uses: tj-actions/changed-files@v42
with:
files_yaml: |
gcc:
- deps/gcc.Dockerfile
- name: Build m68k GCC (only if changed)
if: steps.changed-files.outputs.gcc_any_changed == 'true'
uses: docker/build-push-action@v5
with:
file: deps/gcc.Dockerfile
context: deps/
platforms: ${{ env.PLATFORMS }}
tags: ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest
push: false
load: true

# Push is a separate step so the build logs are clearly separate from the
# push logs.
- name: Push m68k GCC (only if changed, only on push event)
if: steps.changed-files.outputs.gcc_any_changed == 'true' && github.event_name == 'push'
run: |
docker image push ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest
# Right after forking SGDK, the fork will not have a GCC image.
# We may need to fetch the latest from upstream before building SGDK.
- name: Bootstrap m68k GCC
if: steps.changed-files.outputs.gcc_any_changed == 'false'
run: |
# Pull from the user's fork, fall back to the upstream repo.
if ! docker pull ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest; then
docker pull ghcr.io/stephane-d/sgdk-m68k-gcc:latest
docker tag ghcr.io/stephane-d/sgdk-m68k-gcc:latest \
ghcr.io/${{ github.actor }}/sgdk-m68k-gcc:latest
# Note that we are not pushing the upstream version to the fork.
# The workflow will update the fork if/when the GCC Dockerfile
# changes in "master", even if those changes come from upstream.
fi
- name: Build SGDK
uses: docker/build-push-action@v5
with:
file: Dockerfile
context: .
platforms: ${{ env.PLATFORMS }}
build-args: |
BASE_IMAGE=ghcr.io/${{ github.actor }}/sgdk-m68k-gcc
tags: ghcr.io/${{ github.actor }}/sgdk:latest
push: false
load: true

# Push is a separate step so the build logs are clearly separate from the
# push logs.
- name: Push SGDK (only on push event)
if: github.event_name == 'push'
run: |
docker image push ghcr.io/${{ github.actor }}/sgdk:latest
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ tools/rescomp/format
tools/rescomp/rescomp.jar
tools/xgm rom builder/bin
src/z80_*.h
/.idea
*.iml
131 changes: 105 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,115 @@
FROM amd64/ubuntu:20.04

# Set-up argument defaults
ARG ALPINE_VERSION=3.18.3
ARG JDK_VER=11

# Install supporting packages
RUN dpkg --add-architecture i386 \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
bash \
make \
openjdk-${JDK_VER}-jre-headless \
wine32 \
&& rm -rf /var/lib/apt/lists/*
ARG BASE_IMAGE=ghcr.io/stephane-d/sgdk-m68k-gcc
ARG BASE_IMAGE_VERSION=latest

# Create sgdk unprivileged user
RUN useradd -ms /bin/sh -d /sgdk sgdk

# Set-up SGDK
# Stage Zero - Base images for m68k compiler and JRE
FROM $BASE_IMAGE:$BASE_IMAGE_VERSION as m68k-files

FROM alpine:$ALPINE_VERSION as jre-minimal
ARG JDK_VER
RUN apk add --no-cache openjdk${JDK_VER}
ENV JRE_MODULES="java.base,java.desktop,java.xml"
RUN jlink \
--module-path "$JAVA_HOME/jmods" \
--add-modules $JRE_MODULES \
--verbose \
--strip-debug \
--compress 2 \
--no-header-files \
--no-man-pages \
--output /opt/jre-minimal


# Stage One - build all tools and libs for SGDK
FROM jre-minimal as build
RUN apk add --no-cache build-base git

# Set-up environment and folders
ENV SGDK_PATH=/sgdk
RUN mkdir -p $SGDK_PATH/bin

# Building sjasm
ENV SJASMEP_DIR="/tmp/sjasmep"
RUN git clone https://github.com/istvan-v/sjasmep.git $SJASMEP_DIR
WORKDIR $SJASMEP_DIR
RUN make
RUN mv $SJASMEP_DIR/sjasm $SGDK_PATH/bin/

# Get SGDK sources
COPY . /sgdk
ENV GDK=/sgdk
ENV SGDK_DOCKER=y

# Create wrappers to execute .exe files using wine
RUN sed -i 's/\r$//' sgdk/bin/create-bin-wrappers.sh && \
chmod +x sgdk/bin/create-bin-wrappers.sh

RUN sgdk/bin/create-bin-wrappers.sh
# Building bintos
WORKDIR $SGDK_PATH/tools/bintos
RUN gcc -O2 -s src/bintos.c -o $SGDK_PATH/bin/bintos

# Building xgmtool
WORKDIR $SGDK_PATH/tools/xgmtool
RUN gcc -fexpensive-optimizations -Os -s src/*.c -o $SGDK_PATH/bin/xgmtool

# Building apj.jar
WORKDIR $SGDK_PATH/tools/apj/src
RUN javac sgdk/aplib/*.java
RUN jar cfe $SGDK_PATH/bin/apj.jar sgdk.aplib.Launcher sgdk/aplib/*.class

# Building lz4w.jar
WORKDIR $SGDK_PATH/tools/lz4w/src
RUN javac sgdk/lz4w/*.java
RUN jar cfe $SGDK_PATH/bin/lz4w.jar sgdk.lz4w.Launcher sgdk/lz4w/*.class

# Building sizebnd.jar
WORKDIR $SGDK_PATH/tools/sizebnd/src
RUN javac sgdk/sizebnd/*.java
RUN jar cfe $SGDK_PATH/bin/sizebnd.jar sgdk.sizebnd.Launcher sgdk/sizebnd/*.class

# Set-up mount point and make command
# Building rescomp.jar
WORKDIR $SGDK_PATH/tools/rescomp/src
ENV CLASSPATH="$SGDK_PATH/bin/apj.jar:$SGDK_PATH/bin/lz4w.jar:$SGDK_PATH/tools/rescomp/src"
RUN cp -r $SGDK_PATH/tools/commons/src/sgdk .
RUN find . -name "*.java" | xargs javac
RUN echo -e "Main-Class: sgdk.rescomp.Launcher\nClass-Path: apj.jar lz4w.jar" > Manifest.txt
RUN jar cfm $SGDK_PATH/bin/rescomp.jar Manifest.txt .

# Copy m68k compiler from base image
COPY --from=m68k-files /m68k/ /usr/
ENV PATH="$SGDK_PATH/bin:${PATH}"

# Build SGDK libraries
WORKDIR $SGDK_PATH
RUN mkdir lib
#build libmd.a
RUN make -f makelib.gen release
#build libmd_debug.a
RUN make -f makelib.gen debug
RUN rm -rf $SGDK_PATH/tools


# Stage Two - copy tools into a clean image
FROM alpine:$ALPINE_VERSION
RUN apk add --no-cache build-base

# Copy m68k compiler from base image
COPY --from=m68k-files /m68k/ /usr/

# Copy JRE from base image
COPY --from=jre-minimal /opt/jre-minimal /opt/jre-minimal
ENV JAVA_HOME=/opt/jre-minimal
ENV PATH="$PATH:$JAVA_HOME/bin"

# Set-up SGDK
ENV SGDK_PATH=/sgdk

# Create sgdk unprivileged user
RUN addgroup -S sgdk && adduser -S sgdk -G sgdk -h $SGDK_PATH

# Copy SGDK tools and libraries
COPY --from=build --chown=sgdk:sgdk $SGDK_PATH $SGDK_PATH

# Set-up mount point, user, and make command
VOLUME /src
WORKDIR /src

# Use sgdk user
USER sgdk
ENTRYPOINT [ "make", "-f", "/sgdk/makefile.gen" ]
ENV PATH="$SGDK_PATH/bin:${PATH}"
ENTRYPOINT ["/bin/sh","-c","make -f $SGDK_PATH/makefile.gen $@", "--"]
59 changes: 0 additions & 59 deletions Dockerfile-m1

This file was deleted.

17 changes: 0 additions & 17 deletions bin/create-bin-wrappers.sh

This file was deleted.

Loading