Skip to content

Commit

Permalink
Use upon instead of handlebars
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Jul 15, 2023
1 parent 1cabc19 commit 6612086
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 218 deletions.
212 changes: 20 additions & 192 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
name = "sheldon-cross"
version = "0.0.0"
authors = ["Ross MacArthur <ross@macarthur.io>"]
edition = "2018"
edition = "2021"
publish = false

[dependencies]
anyhow = "1.0.54"
clap = { version = "3.1.1", features = ["derive"] }
handlebars = "4.2.1"
serde_json = "1.0.79"
upon = "0.6.0"

[[bin]]
name = "sheldon-cross"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# sheldon-cross

[![Build status](https://img.shields.io/github/workflow/status/rossmacarthur/sheldon-cross/build/trunk)](https://github.com/rossmacarthur/locks/actions?query=workflow%3Abuild)
[![Docker repo](https://img.shields.io/badge/docker-latest-blue)](https://hub.docker.com/r/rossmacarthur/sheldon-cross)
[![Build status](https://img.shields.io/github/actions/workflow/status/rossmacarthur/sheldon/build.yaml?branch=trunk)](https://github.com/rossmacarthur/sheldon-cross/actions/workflows/build.yaml?query=branch%3Atrunk)
[![Docker repo](https://img.shields.io/badge/docker-latest-blue)](https://hub.docker.com/r/rossmacarthur/sheldon-cross)

*Docker images for [sheldon](https://github.com/rossmacarthur/sheldon) CI.*

Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FROM rustembedded/cross:{{target}}
FROM ghcr.io/cross-rs/{{target}}:latest

COPY install_openssl.sh /
RUN bash /install_openssl.sh {{install_openssl_args}}

ENV OPENSSL_DIR=/openssl \
{{#if is_musl }}
{% if is_musl -%}
OPENSSL_STATIC=1 \
{{else}}
{% else -%}
LD_LIBRARY_PATH="/openssl/lib:${LD_LIBRARY_PATH}" \
{{/if}}
{% endif -%}
OPENSSL_INCLUDE_DIR=/openssl/include \
OPENSSL_LIB_DIR=/openssl/lib
2 changes: 1 addition & 1 deletion docker/install_openssl.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
#
# Copied from https://github.com/rust-embedded/cross/blob/v0.1.16/docker/openssl.sh
# Copied from https://github.com/cross-rs/cross/blob/v0.1.16/docker/openssl.sh

set -ex

Expand Down
31 changes: 15 additions & 16 deletions render.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use std::fs;
use std::path::PathBuf;

use anyhow::Context;
use anyhow::{anyhow, Context};
use clap::Parser;
use handlebars::Handlebars;
use serde_json::json;

const TEMPLATE: &str = include_str!("docker/Dockerfile");

Expand All @@ -26,24 +24,25 @@ struct Opts {

fn main() -> anyhow::Result<()> {
let opts = Opts::parse();
let mut handlebars = Handlebars::new();
handlebars.set_strict_mode(true);
handlebars
.register_template_string("dockerfile", TEMPLATE)
.context("failed to register template")?;

let data = upon::value! {
target: &opts.target,
is_musl: &opts.target.contains("musl"),
install_openssl_args: opts.install_openssl_args,
};

let rendered = upon::Engine::new()
.compile(TEMPLATE)
.map_err(|err| anyhow!("{:?}", err))?
.render(data)?;

let path: PathBuf = ["docker", &format!("Dockerfile.{}", opts.target)]
.iter()
.collect();
let data = json!({
"target": opts.target,
"is_musl": opts.target.contains("musl"),
"install_openssl_args": opts.install_openssl_args,
});
let rendered = handlebars
.render("dockerfile", &data)
.context("failed to render Dockerfile")?;

fs::write(&path, &rendered)
.with_context(|| format!("failed to write to `{}`", path.display()))?;

eprintln!("Rendered `{}`\n", path.display());
println!("{}", rendered);
Ok(())
Expand Down

0 comments on commit 6612086

Please sign in to comment.