Skip to content

plugin: Add resource bundles defined in Package.swift to container images #78

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

Merged
merged 4 commits into from
Apr 11, 2025

Conversation

euanh
Copy link
Collaborator

@euanh euanh commented Apr 9, 2025

Motivation

A target in Package.swift can include resources. When the target is built, the resources are copied into a bundle directory and a Bundle class is generated, giving the executable a convenient way to retrieve them at run time.

A target with resources should be able to access them when it is packaged in a container image. For example, a web server might bundle resources such as images or fonts.

Fixes #48

Modifications

  • Add a new --resource parameter to containertool. This specifies a resource bundle directory which is added to the container image using the directory archiving support added to the Tar module in tar: Add support for archiving directories #74. When containertool is used alone, multiple --resource flags can be specified and will be added to the image in the order in which they appear on the command line. A target in Package.swift can only define one resource bundle, so when used through the plugin only one bundle will be added.
  • Update the plugin to pass the --resource flag to containertool when an executable target has resources.

Result

If a target includes resources, the resource bundle will be copied into the container image at a path where the generated Bundle class can find it.
If a target does not include resources, the container image will only include the executable.

Test Plan

  • Existing tests continue to pass.
  • New integration tests verify that all expected resources are present.

@euanh euanh force-pushed the feature/resources branch 4 times, most recently from 5de57c3 to 43e7d4f Compare April 9, 2025 16:57
@euanh euanh added kind/enhancement New feature or request semver/minor Adds new public API. labels Apr 9, 2025
@euanh euanh changed the title Feature/resources plugin: Add resource bundles defined in Package.swift to container images Apr 10, 2025
@euanh euanh marked this pull request as ready for review April 10, 2025 11:08
@euanh euanh force-pushed the feature/resources branch 5 times, most recently from 8196e0a to 67f072e Compare April 10, 2025 15:59
@euanh euanh force-pushed the feature/resources branch 2 times, most recently from 7f298e6 to 320ad63 Compare April 11, 2025 09:21
@euanh euanh merged commit 1d1fac5 into apple:main Apr 11, 2025
21 checks passed
@euanh euanh deleted the feature/resources branch April 11, 2025 09:35
euanh added a commit that referenced this pull request Apr 14, 2025
Motivation
----------

An example showing how to use resources (#78) is helpful for new users
and can be used as an end to end tests for this feature.

Modifications
-------------

* Add a new `HelloWorldWithResources` example
* Add the new example to the `End to end tests` GitHub Actions job
* Restructure the end to end tests to check the HTTP response code
instead of the content which is returned, because the new test returns
one of 3 JPEGs selected at random, whereas the existing tests returned
strings.
* Adopt the code structure used by the [official Hummingbird
examples](https://github.com/hummingbird-project/hummingbird-examples),
to make it more familiar to users who are used to the official examples.
 
Result
------

* The repository contains a new example showing how to use resources in
a container image
* The resource feature is tested as part of the automated end to end
test suite.

Test Plan
---------

The new test passes and all existing tests continue to pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The container image should include any resources associated with the target being packaged
1 participant