Simple HTML / CSS / Webasm (Rust Yew) image gallery made for my cat and deployed with Docker.
Yew Documentation
·
Report Bug
·
Request Feature
Table of Contents
This project is an image gallery application that dynamically generates a JSON list of images from a specified directory. It uses Nginx to serve the content and monitors the images directory for any changes, updating the JSON file accordingly. The application is containerised using Docker and integrated with GitHub Actions for continuous integration and deployment.
The project is organised as follows:
image_gallery/
├── Cargo.toml
├── generate_images_json.sh # Script to serve as a local "API" discovering the images
├── static/
│ ├── images/
│ ├── resources/
│ └── images.json # Needed for the page to know what images to load
└── src/
├── main.rs
├── models.rs # Data structures
├── router.rs # Define the URL routes
├── components/
│ ├── gallery.rs
│ └── mod.rs
├── pages/
│ ├── home.rs
│ └── mod.rs
main.rs
: Entrypoint of the application.models.rs
: Contains data structures for counters and SVG options.router.rs
: Controls the directing of the URL (just / our case)components/gallery.rs
: Fetches the images and generates the grid with them.pages/home.rs
: Contains the main logic and HTML code.
Follow these instructions to set up a local instance of the Image Gallery.
Note
You have to build this locally or fork this repository to be able to modify the HTML to your liking.
- Rust installed (includes Cargo)
- WebAssembly target
rustup target add wasm32-unknown-unknown
- Trunk
cargo install --locked trunk
- (Optional) Docker if you plan to deploy in a container
-
Clone the repository:
git clone https://github.com/AitorAstorga/image_gallery.git cd image_gallery
-
Modify the HTML
-
Edit the File: Open
/src/pages/home.rs
. It contains the HTML (and Yew component code) for the home page. -
Make Your Changes: Update the HTML, styles, or layout as desired. Remember that because this is a Rust Yew app, any UI changes will require a rebuild for them to take effect.
-
-
Run the application locally:
trunk serve --address 0.0.0.0
By default, Yew runs on localhost:8080
.
You have two options to deploy your changes:
You can use GitHub Actions to automatically build the project and push a Docker image to GitHub Container Registry (ghcr.io).
-
Ensure the Workflow Exists: Check that your fork contains the GitHub Actions workflow (found in .github/workflows/). It should be configured to build your project and push the image.
-
Configure Repository Secrets: In your forked repository, set up the following secrets (via Settings > Secrets and variables > Actions):
GHCR_TOKEN
: Your GitHub Container Registry Personal Access Token.- (Any other secrets required by your workflow.)
-
Commit and Push Your Changes:
git add . git commit -m "Customize home page HTML" git push origin main
The GitHub Actions workflow will trigger automatically, build your project, and push the Docker image to:
ghcr.io/<your-username>/aichan-image-gallery:latest
-
Update docker-compose (if needed): If you use Docker Compose, update the image reference in your
docker-compose.yml
to point to your custom image.A sample. Keep in mind this will use my image, you should make your own.
services: web: container_name: image-gallery image: ghcr.io/aitorastorga/aichan-image-gallery:latest ports: - "YOUR_PORT:80" volumes: - /PATH_TO_YOUR_IMAGES:/usr/share/nginx/html/static/images restart: unless-stopped
If you prefer local container builds, use the provided Dockerfile
:
-
Build the Docker Image:
docker build -t your-image-name .
-
Run the Container:
docker run -d -p YOUR_PORT:80 your-image-name
-
Update docker-compose.yml (Optional): If you deploy with Docker Compose, modify the image field in docker-compose.yml to use your newly built image.
Note
Reminder: Every time you modify the UI or other front-end code (such as /src/pages/home.rs), be sure to rebuild your project (or Docker image) so that your changes are included in your deployment.
Contributions are welcome! Please fork the repository, make your changes, and open a pull request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the European Union Public License v1.2. See LICENSE
for more information.
Aitor Astorga Saez de Vicuña - [email protected]
Project Link: https://github.com/AitorAstorga/image_gallery
Thanks to these nice projects!
- Rust Yew A framework for creating reliable and efficient web applications.