Compare commits

...

2 Commits

Author SHA1 Message Date
94d28ee047 Update readme (#46)
All checks were successful
Rust Build / Check (push) Successful in 59s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / build (push) Successful in 37s
Rust Build / Test Suite (push) Successful in 1m15s
Rust Build / Clippy (push) Successful in 1m19s
Reviewed-on: #46
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-25 18:50:45 +00:00
bd01dac544 tsk-42: Dockerize the service (#44)
All checks were successful
Rust Build / Check (push) Successful in -9s
Rust Build / Rustfmt (push) Successful in -12s
Rust Build / Test Suite (push) Successful in 37s
Rust Build / Clippy (push) Successful in -8s
Rust Build / build (push) Successful in 41s
Closes #42

Reviewed-on: #44
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-08-16 23:12:05 +00:00
8 changed files with 145 additions and 98 deletions

18
.dockerignore.yaml Normal file
View File

@@ -0,0 +1,18 @@
# Ignore build artifacts
target/
pkg/
# Ignore git directory
.git/
.gitea/
# Ignore environment files (configure via docker-compose instead)
.env*
# Ignore IDE/editor specific files
.idea/
.vscode/
# Ignore OS specific files
*.DS_Store

View File

@@ -1,4 +1,4 @@
ROOT_DIRECTORY=/home/songparser/mydata
ICARUS_BASE_API_URL=http://localhost:3000
ICARUS_AUTH_BASE_API_URL=http://localhost:3001
ROOT_DIRECTORY=/usr/local/bin
ICARUS_BASE_API_URL=http://api:3000
ICARUS_AUTH_BASE_API_URL=http://auth_api:3000
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH

34
Cargo.lock generated
View File

@@ -517,7 +517,7 @@ dependencies = [
[[package]]
name = "icarus_envy"
version = "0.3.2"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2-18-d498f60046-006#d498f600468c7e5fcf03a640f8c5b9476765fe96"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.2#d84a8144aedf02e1b459d67c4023a7e0833f89fd"
dependencies = [
"const_format",
"dotenvy",
@@ -533,14 +533,15 @@ dependencies = [
[[package]]
name = "icarus_models"
version = "0.5.5"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.5-devel-bd793db08e-111#bd793db08e06b256ffecd9f4528e55e3026fede7"
version = "0.5.6"
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.6#2d6b550ae6721b41ecc3039799f6a5e873869077"
dependencies = [
"josekit",
"rand",
"serde",
"serde_json",
"time",
"utoipa",
"uuid",
]
@@ -659,6 +660,7 @@ checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e"
dependencies = [
"equivalent",
"hashbrown",
"serde",
]
[[package]]
@@ -1318,7 +1320,7 @@ dependencies = [
[[package]]
name = "songparser"
version = "0.2.5"
version = "0.3.0"
dependencies = [
"futures",
"icarus_envy",
@@ -1644,6 +1646,30 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
[[package]]
name = "utoipa"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fcc29c80c21c31608227e0912b2d7fddba57ad76b606890627ba8ee7964e993"
dependencies = [
"indexmap",
"serde",
"serde_json",
"utoipa-gen",
]
[[package]]
name = "utoipa-gen"
version = "5.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d79d08d92ab8af4c5e8a6da20c47ae3f61a0f1dabc1997cdf2d082b757ca08b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"uuid",
]
[[package]]
name = "uuid"
version = "1.17.0"

View File

@@ -1,6 +1,6 @@
[package]
name = "songparser"
version = "0.2.5"
version = "0.3.0"
edition = "2024"
rust-version = "1.88"
@@ -14,5 +14,5 @@ time = { version = "0.3.41", features = ["macros", "serde"] }
uuid = { version = "1.17.0", features = ["v4", "serde"] }
rand = { version = "0.9.1" }
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.5-devel-bd793db08e-111" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2-18-d498f60046-006" }
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.6" }
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.2" }

63
Dockerfile Normal file
View File

@@ -0,0 +1,63 @@
# Stage 1: Build the application
# Use a specific Rust version for reproducibility. Choose one that matches your development environment.
# Using slim variant for smaller base image
FROM rust:1.88 as builder
# Set the working directory inside the container
WORKDIR /usr/src/app
# Install build dependencies if needed (e.g., git for cloning)
RUN apt-get update && apt-get install -y --no-install-recommends \
pkg-config libssl3 \
ca-certificates \
openssh-client git \
&& rm -rf /var/lib/apt/lists/*
# << --- ADD HOST KEY HERE --- >>
# Replace 'yourgithost.com' with the actual hostname (e.g., github.com)
RUN mkdir -p -m 0700 ~/.ssh && \
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
# Copy Cargo manifests
COPY Cargo.toml Cargo.lock ./
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
RUN --mount=type=ssh mkdir src && \
echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs && \
cargo build --release --quiet && \
rm -rf src target/release/deps/songparser* # Clean up dummy build artifacts (replace songparser)
# Copy the actual source code
COPY src ./src
# If you have other directories like `templates` or `static`, copy them too
COPY .env ./.env
# << --- SSH MOUNT ADDED HERE --- >>
# Build *only* dependencies to leverage Docker cache
# This dummy build caches dependencies as a separate layer
# Mount the SSH agent socket for this command
RUN --mount=type=ssh \
cargo build --release --quiet
# Stage 2: Create the final, smaller runtime image
# Use a minimal base image like debian-slim or even distroless for security/size
FROM ubuntu:24.04
# Install runtime dependencies if needed (e.g., SSL certificates)
RUN apt-get update && apt-get install -y ca-certificates libssl-dev libssl3 && rm -rf /var/lib/apt/lists/*
# Set the working directory
WORKDIR /usr/local/bin
# Copy the compiled binary from the builder stage
# Replace 'songparser' with the actual name of your binary (usually the crate name)
COPY --from=builder /usr/src/app/target/release/songparser .
# Copy other necessary files like .env (if used for runtime config) or static assets
# It's generally better to configure via environment variables in Docker though
COPY --from=builder /usr/src/app/.env .
# Set the command to run your application
# Ensure this matches the binary name copied above
CMD ["./songparser"]

View File

@@ -1,93 +1,20 @@
# Songparser
A service that edits the metadata of a queued song and populates it with data.
## Getting started
This service can run as a regular service or a docker image. The easiest way to get quickly
started is to run it with docker. Copy `.env.docker.sample` as `.env`. Ensure that
`ROOT_DIRECTORY` is pointing to a directory that exists, not for the local filesystem, but
for the filesystem on the docker image. The current directory that is listed will work, but
it can be changed.
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
The `SERVICE_PASSPHRASE` env variable should not be changed, but it could be changed. The
value for this variable should match the value in the `passphrase` table. This would be
found in the `icarus_auth` project.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
Ensure that the URLs for the two APIs are correctly set for the respective env variables
`ICARUS_BASE_API_URL` for Icarus API and `ICARUS_AUTH_BASE_API_URL` for `icarus_auth`.
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.com/kdeng00/songparser.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.com/kdeng00/songparser/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing (SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thanks to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
If the values are properly set, next is to build the image. The docker image should be
built from the main icarus web API.

12
docker-compose.yaml Normal file
View File

@@ -0,0 +1,12 @@
version: '3.8' # Use a recent version
services:
# Your Rust Application Service
songparser:
build: # Tells docker-compose to build the Dockerfile in the current directory
context: .
ssh: ["default"] # Uses host's SSH agent
container_name: songparser # Optional: Give the container a specific name
env_file:
- .env
restart: unless-stopped # Optional: Restart policy

View File

@@ -16,6 +16,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url().await,
..Default::default()
};
println!("Base URL: {:?}", app.uri);
println!("Auth URL: {:?}", app.auth_uri);
match auth::get_token(&app).await {
Ok(login_result) => {
app.token = login_result;
@@ -27,8 +30,6 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
};
loop {
println!("Base URL: {:?}", app.uri);
println!("Auth URL: {:?}", app.auth_uri);
println!("Token: {:?}", app.token);
if auth::did_token_expire(&app.token).await {