Skip to content

Commit

Permalink
Add native docker images w/ build workflow
Browse files Browse the repository at this point in the history
Rebased, cleaned-up version of PR Stephane-D#292, which adds Docker images that
do not rely on Wine, with a GitHub Actions workflow to build and push
Docker images to ghcr.io.

Compared with Stephane-D#292, this:
 - is based on 4397ac2 (2024-03-06) instead of d84d456 (2023-07-31)
 - has no changes to newline styless, so the diff is easier to read
 - adds instructions to readme.md on building deps/gcc.Dockerfile
 - fix case on gcc docker image (must be lowercase apparently)
 - fixes typos
 - streamlines and simplifies the GitHub Actions workflow
 - disables arm64 image builds because they keep hanging in the GitHub
   Actions environment

Resolves Stephane-D#290
  • Loading branch information
justgook authored and joeyparrish committed Mar 11, 2024
1 parent 4397ac2 commit d2c638f
Show file tree
Hide file tree
Showing 11 changed files with 465 additions and 183 deletions.
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
107 changes: 107 additions & 0 deletions .github/workflows/sgdk-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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
# NOTE: If you are seeing failures in this job right after forking SGDK,
# you may need to bootstrap the base image into your fork on ghcr.io.
# This can be done with:
# docker image pull ghcr.io/stephane-d/sgdk-m68k-gcc:latest
# docker image tag ghcr.io/stephane-d/sgdk-m68k-gcc:latest \
# ghcr.io/YOUR_NAMEE/sgdk-m68k-gcc:latest
# gh auth token | docker login ghcr.io -u YOUR_NAME --password-stdin
# docker image push ghcr.io/YOUR_NAMEE/sgdk-m68k-gcc:latest
- 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
129 changes: 105 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,117 @@
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
# Stage Zero - just init image to download files in other stages
FROM $BASE_IMAGE:$BASE_IMAGE_VERSION as m68k-files


FROM alpine:$ALPINE_VERSION as jdk-base
ARG JDK_VER
RUN apk add --no-cache openjdk${JDK_VER}



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

# Set-up SGDK
COPY . /sgdk
ENV GDK=/sgdk
ENV SGDK_DOCKER=y
WORKDIR /sgdk
COPY . .
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/

# 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

# 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"
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 --from=m68k-files /m68k/ /usr/
ENV PATH="$SGDK_PATH/bin:${PATH}"

# 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
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



FROM jdk-base as jre-minimal
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


### Second Stage - clean image ###
FROM alpine:$ALPINE_VERSION
RUN apk add --no-cache build-base

COPY --from=m68k-files /m68k/ /usr/

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 --from=build --chown=sgdk:sgdk $SGDK_PATH $SGDK_PATH

ENV PATH="$SGDK_PATH/bin:${PATH}"

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

# Use sgdk user
USER sgdk
ENTRYPOINT [ "make", "-f", "/sgdk/makefile.gen" ]
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

0 comments on commit d2c638f

Please sign in to comment.