-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CI -> Publish docker image on release builds
- Loading branch information
1 parent
d65c11e
commit 1028d71
Showing
10 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use std::process::Command; | ||
|
||
use crate::core::constants::workspace_dir; | ||
use crate::core::types::Package; | ||
use crate::core::util::RunRequiringSuccess; | ||
|
||
/// Build and publish a Docker image | ||
#[derive(Debug, clap::Parser)] | ||
pub struct DockerCli {} | ||
|
||
const OPENDUT_DOCKER_IMAGE_HOST: &str = "ghcr.io"; | ||
const OPENDUT_DOCKER_IMAGE_NAMESPACE: &str = "eclipse-opendut"; | ||
fn carl_container_uri() -> String { | ||
let image_host = std::env::var("OPENDUT_DOCKER_IMAGE_HOST").unwrap_or(OPENDUT_DOCKER_IMAGE_HOST.to_string()); | ||
let image_namespace = std::env::var("OPENDUT_DOCKER_IMAGE_NAMESPACE").unwrap_or(OPENDUT_DOCKER_IMAGE_NAMESPACE.to_string()); | ||
let image_uri = format!("{}/{}/{}:{}", image_host, image_namespace, Package::Carl.ident(), crate::build::PKG_VERSION); | ||
image_uri | ||
} | ||
|
||
pub fn build_carl_docker_image() -> crate::Result { | ||
let image_version_build_arg = format!("VERSION={}", crate::build::PKG_VERSION); | ||
let now = chrono::Utc::now().naive_utc(); | ||
|
||
// https://github.com/opencontainers/image-spec/blob/main/annotations.md | ||
let source = format!("org.opencontainers.image.source={}", crate::core::metadata::repository_url()); | ||
let url = format!("org.opencontainers.image.url={}", carl_container_uri()); | ||
let version = format!("org.opencontainers.image.version={}", crate::build::PKG_VERSION); | ||
let created = format!("org.opencontainers.image.created={}", now); | ||
let revision = format!("org.opencontainers.image.revision={}", crate::build::COMMIT_HASH); | ||
|
||
Command::new("docker") | ||
.current_dir(workspace_dir()) | ||
.args([ | ||
"build", | ||
"--file", | ||
".ci/docker/carl/Dockerfile", | ||
"--build-arg", | ||
&image_version_build_arg, | ||
"--label", &source, | ||
"--label", &url, | ||
"--label", &version, | ||
"--label", &created, | ||
"--label", &revision, | ||
"--tag", | ||
&carl_container_uri(), | ||
".", | ||
]) | ||
.run_requiring_success()?; | ||
Ok(()) | ||
} | ||
|
||
pub fn publish_carl_docker_image() -> crate::Result { | ||
Command::new("docker") | ||
.current_dir(workspace_dir()) | ||
.args(["push", &carl_container_uri()]) | ||
.run_requiring_success()?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ pub mod build; | |
pub mod check; | ||
pub mod distribution; | ||
pub mod doc; | ||
pub mod docker; | ||
pub mod licenses; | ||
pub mod run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: publish-docker | ||
on: | ||
workflow_call: # allow this workflow to be called from other workflows | ||
inputs: | ||
runs-on: | ||
default: "['ubuntu-latest']" | ||
required: false | ||
type: string | ||
|
||
jobs: | ||
publish-docker: | ||
name: "Publish docker" | ||
runs-on: ${{ fromJson(inputs.runs-on) }} | ||
permissions: | ||
contents: write | ||
packages: write | ||
|
||
steps: | ||
- name: Checkout Sources | ||
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab | ||
- name: Rust setup | ||
uses: ./.github/actions/rust-setup | ||
|
||
- name: Download opendut-CARL bundle | ||
uses: actions/download-artifact@6b208ae046db98c579e8a3aa621ab581ff575935 | ||
with: | ||
name: "opendut-carl-x86_64-unknown-linux-gnu-${{ github.sha }}.tar.gz" | ||
path: "./target/ci/distribution/x86_64-unknown-linux-gnu/" | ||
|
||
- name: Publish Docker image | ||
run: cargo ci carl docker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters