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

Conversation

joeyparrish
Copy link
Contributor

@joeyparrish joeyparrish commented Mar 10, 2024

Rebased, cleaned-up version of PR #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 #292, this:

  • is based on 4397ac2 (2024-03-06) instead of d84d456 (2023-07-31)
  • has no changes to newline styles, so the diff is easier to read
  • adds instructions to readme.md on building deps/gcc.Dockerfile
  • fixes 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 #290
Resolves #304

@joeyparrish joeyparrish mentioned this pull request Mar 10, 2024
@joeyparrish
Copy link
Contributor Author

I'm debugging and streamlining the workflows on my fork. I'll convert this to a draft for now until that process is complete. Sorry for the noise!

@joeyparrish joeyparrish marked this pull request as draft March 11, 2024 17:00
@joeyparrish joeyparrish changed the title Add multi-platform docker image Add native docker images w/ build workflow Mar 11, 2024
@joeyparrish joeyparrish force-pushed the docker branch 2 times, most recently from d2c638f to 328de48 Compare March 11, 2024 21:39
@joeyparrish joeyparrish marked this pull request as ready for review March 11, 2024 21:40
@joeyparrish
Copy link
Contributor Author

This is ready now. Please take a look!

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
Resolves Stephane-D#304
@loki666
Copy link

loki666 commented Mar 12, 2024

Nice, could you add git to the second stage image.
It would be handy when using the image in a VS Code devcontainer.

Thanks

makefile.gen Outdated
SRC_S= $(wildcard *.s)
SRC_S+= $(wildcard $(SRC)/*.s)
SRC_S+= $(wildcard $(SRC)/*/*.s)
SRC_S+= $(wildcard $(SRC)/*/*/*.s)
SRC_S:= $(filter-out $(SRC)/boot/sega.s,$(SRC_S))
Copy link
Owner

@Stephane-D Stephane-D Mar 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it was removed ? this line is important so we can add a specific rule to build boot/sega.s file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reverting this. See also my other replies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Owner

@Stephane-D Stephane-D left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments in Dockerfile and mekafile.gen

makefile.gen Outdated
$(CC) $(DEFAULT_FLAGS) -c $< -o $@

$(SRC)/boot/sega.s: $(SRC_LIB)/boot/sega.s
$(OUT)/boot/sega.s: $(SRC_LIB)/boot/sega.s
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you moved boot/sega.s to OUT folder ? The file make be customized (interrupt callback, bootstrap..) so i think it's important to keep it in SRC folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inherited most of these changes from the original PR. I just tried to clean it up for review and fix the workflows.

I'm guessing the original author thought that generated files should go to OUT as a rule, and didn't realize that it could be customized. I would have made the same mistake.

I'll revert this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have run into one problem with these generated sources, though, which I will try to resolve. If I rebuild SGDK, my existing src/boot/rom_head.c gets overwritten when I rebuild my ROM because the one in SRC_LIB is newer. I only noticed because I had already customized my rom_head.c file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted sega.s moving to OUT. Fixed overwritten boot files.

Dockerfile Outdated
Comment on lines 43 to 64
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 link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any interest in rebuilding the JAR file here instead of just copying them from the SGDK repo ? JAR should be portable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll look into it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already seems to rebuild the jar from scratch. I deleted the jar from my local repo, reran the Docker build, and everything is fine.

With this Dockerfile, I can delete all .exe, .dll, and .jar files from the repo and be perfectly happy in Linux. Everything built from source, no Wine. Deleting those from the repo would resolve #297, but I'm not sure if that would have negative consequences for Windows users. Should I do it here? In a follow-up PR? Not at all?

Thanks!

@joeyparrish
Copy link
Contributor Author

Nice, could you add git to the second stage image. It would be handy when using the image in a VS Code devcontainer.

I would like to keep this PR focused. When it is merged, and we have build pipelines that automatically publish new Docker images, you could always follow up with a PR to add git. And ultimately, it will be @Stephane-D who decides whether or not to allow that.

makefile.gen Outdated

out/sega.o: $(SRC)/boot/sega.s out/rom_head.bin
$(CC) -x assembler-with-cpp -Wa,--register-prefix-optional,--bitwise-or $(AFLAGS) -c $(SRC)/boot/sega.s -o $@
$(OUT)/sega.o: $(OUT)/boot/sega.s $(OUT)/rom_head.bin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually seem to depend on rom_head.bin, so I'm removing that dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stand corrected. sega.s references rom_head.bin. I didn't realize. I'll add a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

makefile.gen Outdated

clean: cleanobj cleanres cleanlst cleandep
$(RM) -f out.lst out/cmd_ out/symbol.txt out/rom.nm out/rom.wch out/rom.bin
$(RM) -f out.lst $(OUT)/cmd_ $(OUT)/symbol.txt $(OUT)/rom.nm $(OUT)/rom.wch $(OUT)/rom.bin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what out.lst is exactly, but it looks like it belongs in $(OUT), so I'm moving it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Dockerfile Outdated
ENV GDK=/sgdk
ENV SGDK_DOCKER=y
WORKDIR /sgdk
COPY . .
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reorganizing the steps so more of them can be cached. When I change any one file in SGDK and rebuild, everything past this point must be rerun because the source folder changed and the cache of this step and those after it become stale.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@joeyparrish
Copy link
Contributor Author

@Stephane-D, I believe I have addressed all the feedback so far. My only outstanding question for you is this:

This Dockerfile can regenerate all binaries. I can delete all .exe, .dll, .jar, and .a files from the repo and everything still works from source natively on Linux. Deleting those from the repo would resolve #297, but I'm not sure if that would have negative consequences for Windows users. Should I do it here? In a follow-up PR? Not at all?

Thanks!

@Stephane-D
Copy link
Owner

Stephane-D commented Mar 16, 2024

@Stephane-D, I believe I have addressed all the feedback so far. My only outstanding question for you is this:

This Dockerfile can regenerate all binaries. I can delete all .exe, .dll, .jar, and .a files from the repo and everything still works from source natively on Linux. Deleting those from the repo would resolve #297, but I'm not sure if that would have negative consequences for Windows users. Should I do it here? In a follow-up PR? Not at all?

Thanks!

@joeyparrish Thanks for taking the time to fix all that !
Well about the JAR file rebuild, it's just that i'm afraid that this increase significantly the Docker call. As I understand it, it will rebuild all tools at each time will compile through the Docker call right ?

@joeyparrish
Copy link
Contributor Author

Well about the JAR file rebuild, it's just that i'm afraid that this increase significantly the Docker call. As I understand it, it will rebuild all tools at each time will compile through the Docker call right ?

Those steps (building tools, jars, etc) will only run when someone runs "docker build ..." to create the image from SGDK source. The GitHub Actions workflow will build images every time you push to the master branch. These are all the steps with "RUN".

When a user wants to compile their ROM with SGDK using Docker, the tools will not be rebuilt. It will start at "ENTRYPOINT".

Does this answer your concern?

@joeyparrish
Copy link
Contributor Author

@Stephane-D, let me know if you have other concerns or if you would like me to make other changes. I believe the PR is in a good state. Everything is rebuilt from source at Docker build time in the automated workflow. Each change to the master branch will trigger a new Docker image with native Linux binaries to be published via GitHub. And the Docker image is now based on Alpine Linux instead of Ubuntu, which should make it much smaller and faster to download.

@iratahack
Copy link
Contributor

iratahack commented Mar 22, 2024

@joeyparrish , any thoughts on using crosstool-ng and bulding the latest gcc 13.2.0?

Also, Sjasm sources are included under tools as a submodule. There is no need to clone independently.

@joeyparrish
Copy link
Contributor Author

@joeyparrish , any thoughts on using crosstool-ng and bulding the latest gcc 13.2.0?

Also, Sjasm sources are included under tools as a submodule. There is no need to clone independently.

Looks like it would be useful. I could explore redoing the GCC Dockerfile with crosstool-ng after this PR is merged. Or you could send a PR yourself if you already have experience with crosstool-ng. (I have none.)

@iratahack
Copy link
Contributor

@joeyparrish , any thoughts on using crosstool-ng and bulding the latest gcc 13.2.0?
Also, Sjasm sources are included under tools as a submodule. There is no need to clone independently.

Looks like it would be useful. I could explore redoing the GCC Dockerfile with crosstool-ng after this PR is merged. Or you could send a PR yourself if you already have experience with crosstool-ng. (I have none.)

I have the Dockerfile specific to building the tools using crosstool-ng but I may need some assistance integrating it. Maybe a collaboration? Take a look at the Dockerfile here iratahack@ba9fc47

@joeyparrish
Copy link
Contributor Author

@iratahack, I was hoping to get this PR merged as a baseline before I moved on to improvements, so I would at least be able to refer to the official Docker image from ghcr.io for my own project. But since this hasn't been re-reviewed, I'll take a look at your work and try to integrate it if I can. It may be days to weeks before I have the time, though. Thank you for your offer of collaboration!

@Stephane-D Stephane-D merged commit c6cb89b into Stephane-D:master Mar 29, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

issues in Docker Adding Multi-Platform Docker Images and Build Pipelines to SGDK
5 participants