Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4ed5a7dad5 |
@@ -14,9 +14,6 @@ spec:
|
|||||||
- name: image-name
|
- name: image-name
|
||||||
description: The name for the built image
|
description: The name for the built image
|
||||||
type: string
|
type: string
|
||||||
- name: target-name
|
|
||||||
description: The dockerfile target to build
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
description: The path to the build context
|
description: The path to the build context
|
||||||
type: string
|
type: string
|
||||||
@@ -66,6 +63,8 @@ spec:
|
|||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
params:
|
params:
|
||||||
- name: CONTEXT
|
- name: CONTEXT
|
||||||
value: "$(params.JOB_NAME)"
|
value: "$(params.JOB_NAME)"
|
||||||
@@ -110,7 +109,7 @@ spec:
|
|||||||
- name: revision
|
- name: revision
|
||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/kaniko/0.6/kaniko.yaml
|
value: task/kaniko/0.6//kaniko.yaml
|
||||||
params:
|
params:
|
||||||
- name: IMAGE
|
- name: IMAGE
|
||||||
value: "$(params.image-name):$(tasks.detect-tag.results.tag)"
|
value: "$(params.image-name):$(tasks.detect-tag.results.tag)"
|
||||||
@@ -123,7 +122,6 @@ spec:
|
|||||||
- name: EXTRA_ARGS
|
- name: EXTRA_ARGS
|
||||||
value:
|
value:
|
||||||
- "--destination=$(params.image-name)" # Also write the :latest image
|
- "--destination=$(params.image-name)" # Also write the :latest image
|
||||||
- "--target=$(params.target-name)"
|
|
||||||
- --cache=true
|
- --cache=true
|
||||||
- --cache-copy-layers
|
- --cache-copy-layers
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
||||||
@@ -137,6 +135,8 @@ spec:
|
|||||||
workspace: git-source
|
workspace: git-source
|
||||||
- name: dockerconfig
|
- name: dockerconfig
|
||||||
workspace: docker-credentials
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- detect-tag
|
||||||
finally:
|
finally:
|
||||||
- name: report-success
|
- name: report-success
|
||||||
when:
|
when:
|
||||||
@@ -216,8 +216,6 @@ spec:
|
|||||||
params:
|
params:
|
||||||
- name: image-name
|
- name: image-name
|
||||||
value: "harbor.fizz.buzz/private/webhook-bridge"
|
value: "harbor.fizz.buzz/private/webhook-bridge"
|
||||||
- name: target-name
|
|
||||||
value: ""
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
value: .
|
value: .
|
||||||
- name: path-to-dockerfile
|
- name: path-to-dockerfile
|
||||||
@@ -14,9 +14,6 @@ spec:
|
|||||||
- name: image-name
|
- name: image-name
|
||||||
description: The name for the built image
|
description: The name for the built image
|
||||||
type: string
|
type: string
|
||||||
- name: target-name
|
|
||||||
description: The dockerfile target to build
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
description: The path to the build context
|
description: The path to the build context
|
||||||
type: string
|
type: string
|
||||||
@@ -34,6 +31,8 @@ spec:
|
|||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
params:
|
params:
|
||||||
- name: CONTEXT
|
- name: CONTEXT
|
||||||
value: "$(params.JOB_NAME)"
|
value: "$(params.JOB_NAME)"
|
||||||
@@ -90,7 +89,6 @@ spec:
|
|||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
||||||
- name: EXTRA_ARGS
|
- name: EXTRA_ARGS
|
||||||
value:
|
value:
|
||||||
- "--target=$(params.target-name)"
|
|
||||||
- --cache=true
|
- --cache=true
|
||||||
- --cache-copy-layers
|
- --cache-copy-layers
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
||||||
@@ -104,6 +102,8 @@ spec:
|
|||||||
workspace: git-source
|
workspace: git-source
|
||||||
- name: dockerconfig
|
- name: dockerconfig
|
||||||
workspace: docker-credentials
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
- name: run-cargo-fmt
|
- name: run-cargo-fmt
|
||||||
taskSpec:
|
taskSpec:
|
||||||
metadata: {}
|
metadata: {}
|
||||||
@@ -292,9 +292,7 @@ spec:
|
|||||||
secretName: harbor-plain
|
secretName: harbor-plain
|
||||||
params:
|
params:
|
||||||
- name: image-name
|
- name: image-name
|
||||||
value: "harbor.fizz.buzz/private/webhook-bridge-development-format"
|
value: "harbor.fizz.buzz/private/webhook-bridge-development"
|
||||||
- name: target-name
|
|
||||||
value: ""
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
value: docker/webhook_bridge_development/
|
value: docker/webhook_bridge_development/
|
||||||
- name: path-to-dockerfile
|
- name: path-to-dockerfile
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ spec:
|
|||||||
- name: image-name
|
- name: image-name
|
||||||
description: The name for the built image
|
description: The name for the built image
|
||||||
type: string
|
type: string
|
||||||
- name: target-name
|
|
||||||
description: The dockerfile target to build
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
description: The path to the build context
|
description: The path to the build context
|
||||||
type: string
|
type: string
|
||||||
@@ -34,6 +31,8 @@ spec:
|
|||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
params:
|
params:
|
||||||
- name: CONTEXT
|
- name: CONTEXT
|
||||||
value: "$(params.JOB_NAME)"
|
value: "$(params.JOB_NAME)"
|
||||||
@@ -90,7 +89,6 @@ spec:
|
|||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
||||||
- name: EXTRA_ARGS
|
- name: EXTRA_ARGS
|
||||||
value:
|
value:
|
||||||
- "--target=$(params.target-name)"
|
|
||||||
- --cache=true
|
- --cache=true
|
||||||
- --cache-copy-layers
|
- --cache-copy-layers
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
||||||
@@ -104,6 +102,8 @@ spec:
|
|||||||
workspace: git-source
|
workspace: git-source
|
||||||
- name: dockerconfig
|
- name: dockerconfig
|
||||||
workspace: docker-credentials
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
- name: run-cargo-clippy
|
- name: run-cargo-clippy
|
||||||
taskSpec:
|
taskSpec:
|
||||||
metadata: {}
|
metadata: {}
|
||||||
@@ -271,9 +271,7 @@ spec:
|
|||||||
secretName: harbor-plain
|
secretName: harbor-plain
|
||||||
params:
|
params:
|
||||||
- name: image-name
|
- name: image-name
|
||||||
value: "harbor.fizz.buzz/private/webhook-bridge-development-clippy"
|
value: "harbor.fizz.buzz/private/webhook-bridge-development"
|
||||||
- name: target-name
|
|
||||||
value: ""
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
value: docker/webhook_bridge_development/
|
value: docker/webhook_bridge_development/
|
||||||
- name: path-to-dockerfile
|
- name: path-to-dockerfile
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ spec:
|
|||||||
- name: image-name
|
- name: image-name
|
||||||
description: The name for the built image
|
description: The name for the built image
|
||||||
type: string
|
type: string
|
||||||
- name: target-name
|
|
||||||
description: The dockerfile target to build
|
|
||||||
type: string
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
description: The path to the build context
|
description: The path to the build context
|
||||||
type: string
|
type: string
|
||||||
@@ -34,6 +31,8 @@ spec:
|
|||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
params:
|
params:
|
||||||
- name: CONTEXT
|
- name: CONTEXT
|
||||||
value: "$(params.JOB_NAME)"
|
value: "$(params.JOB_NAME)"
|
||||||
@@ -78,7 +77,7 @@ spec:
|
|||||||
- name: revision
|
- name: revision
|
||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/kaniko/0.6/kaniko.yaml
|
value: task/kaniko/0.6//kaniko.yaml
|
||||||
params:
|
params:
|
||||||
- name: IMAGE
|
- name: IMAGE
|
||||||
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
value: "$(params.image-name):$(tasks.fetch-repository.results.commit)"
|
||||||
@@ -90,7 +89,6 @@ spec:
|
|||||||
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
value: "gcr.io/kaniko-project/executor:v1.12.1"
|
||||||
- name: EXTRA_ARGS
|
- name: EXTRA_ARGS
|
||||||
value:
|
value:
|
||||||
- "--target=$(params.target-name)"
|
|
||||||
- --cache=true
|
- --cache=true
|
||||||
- --cache-copy-layers
|
- --cache-copy-layers
|
||||||
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
- --cache-repo=harbor.fizz.buzz/kanikocache/cache
|
||||||
@@ -104,6 +102,8 @@ spec:
|
|||||||
workspace: git-source
|
workspace: git-source
|
||||||
- name: dockerconfig
|
- name: dockerconfig
|
||||||
workspace: docker-credentials
|
workspace: docker-credentials
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
- name: run-cargo-test
|
- name: run-cargo-test
|
||||||
taskSpec:
|
taskSpec:
|
||||||
metadata: {}
|
metadata: {}
|
||||||
@@ -261,9 +261,7 @@ spec:
|
|||||||
secretName: harbor-plain
|
secretName: harbor-plain
|
||||||
params:
|
params:
|
||||||
- name: image-name
|
- name: image-name
|
||||||
value: "harbor.fizz.buzz/private/webhook-bridge-development-test"
|
value: "harbor.fizz.buzz/private/webhook-bridge-development"
|
||||||
- name: target-name
|
|
||||||
value: ""
|
|
||||||
- name: path-to-image-context
|
- name: path-to-image-context
|
||||||
value: docker/webhook_bridge_development/
|
value: docker/webhook_bridge_development/
|
||||||
- name: path-to-dockerfile
|
- name: path-to-dockerfile
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ spec:
|
|||||||
tasks:
|
tasks:
|
||||||
- name: calculate-tag
|
- name: calculate-tag
|
||||||
runAfter:
|
runAfter:
|
||||||
- fetch-repository
|
- report-pending
|
||||||
workspaces:
|
workspaces:
|
||||||
- name: source
|
- name: source
|
||||||
workspace: git-source
|
workspace: git-source
|
||||||
@@ -77,6 +77,8 @@ spec:
|
|||||||
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
value: df36b3853a5657fd883015cdbf07ad6466918acf
|
||||||
- name: pathInRepo
|
- name: pathInRepo
|
||||||
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
value: task/gitea-set-status/0.1/gitea-set-status.yaml
|
||||||
|
runAfter:
|
||||||
|
- fetch-repository
|
||||||
params:
|
params:
|
||||||
- name: CONTEXT
|
- name: CONTEXT
|
||||||
value: "$(params.JOB_NAME)"
|
value: "$(params.JOB_NAME)"
|
||||||
|
|||||||
@@ -26,6 +26,6 @@ version = "0.0.1"
|
|||||||
|
|
||||||
[[push]]
|
[[push]]
|
||||||
name = "build"
|
name = "build"
|
||||||
source = "pipeline-build-semver.yaml"
|
source = "pipeline-build.yaml"
|
||||||
clone_uri = "git@code.fizz.buzz:talexander/webhook_bridge.git"
|
clone_uri = "git@code.fizz.buzz:talexander/webhook_bridge.git"
|
||||||
branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
branches = [ "^v[0-9]+\\.[0-9]+\\.[0-9]+$" ]
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
cargo-features = ["codegen-backend"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "webhook_bridge"
|
name = "webhook_bridge"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
@@ -59,3 +61,10 @@ tracing-subscriber = { version = "0.3.18", default-features = false, features =
|
|||||||
inherits = "release"
|
inherits = "release"
|
||||||
lto = true
|
lto = true
|
||||||
strip = "symbols"
|
strip = "symbols"
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
codegen-backend = "cranelift"
|
||||||
|
|
||||||
|
[profile.dev.package."*"]
|
||||||
|
codegen-backend = "llvm"
|
||||||
|
opt-level = 3
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ FROM rustlang/rust:nightly-alpine3.20 AS builder
|
|||||||
|
|
||||||
RUN apk add --no-cache musl-dev pkgconfig libressl3.8-libssl libressl-dev
|
RUN apk add --no-cache musl-dev pkgconfig libressl3.8-libssl libressl-dev
|
||||||
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
RUN cargo install --locked --no-default-features --features ci-autoclean cargo-cache
|
||||||
|
RUN rustup component add rustc-codegen-cranelift
|
||||||
RUN rustup component add rustfmt
|
RUN rustup component add rustfmt
|
||||||
RUN rustup component add clippy
|
RUN rustup component add clippy
|
||||||
|
|||||||
@@ -1,7 +1,13 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use kube::Client;
|
||||||
|
|
||||||
|
use crate::gitea_client::GiteaClient;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct AppState {
|
pub(crate) struct AppState {
|
||||||
|
pub(crate) kubernetes_client: Client,
|
||||||
|
pub(crate) gitea: GiteaClient,
|
||||||
pub(crate) allowed_repos: Arc<HashSet<String>>,
|
pub(crate) allowed_repos: Arc<HashSet<String>>,
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/lib.rs
10
src/lib.rs
@@ -47,6 +47,14 @@ pub async fn init_tracing() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn launch_server() -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn launch_server() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let kubernetes_client: Client = Client::try_default()
|
||||||
|
.await
|
||||||
|
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
||||||
|
|
||||||
|
let gitea_api_root = std::env::var("WEBHOOK_BRIDGE_API_ROOT")?;
|
||||||
|
let gitea_api_token = std::env::var("WEBHOOK_BRIDGE_OAUTH_TOKEN")?;
|
||||||
|
let gitea = GiteaClient::new(gitea_api_root, gitea_api_token);
|
||||||
|
|
||||||
let allowed_repos = std::env::var("WEBHOOK_BRIDGE_REPO_WHITELIST")?;
|
let allowed_repos = std::env::var("WEBHOOK_BRIDGE_REPO_WHITELIST")?;
|
||||||
let allowed_repos: HashSet<_> = allowed_repos
|
let allowed_repos: HashSet<_> = allowed_repos
|
||||||
.split(",")
|
.split(",")
|
||||||
@@ -65,6 +73,8 @@ pub async fn launch_server() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
TimeoutLayer::new(Duration::from_secs(600)),
|
TimeoutLayer::new(Duration::from_secs(600)),
|
||||||
))
|
))
|
||||||
.with_state(AppState {
|
.with_state(AppState {
|
||||||
|
kubernetes_client,
|
||||||
|
gitea,
|
||||||
allowed_repos: Arc::new(allowed_repos),
|
allowed_repos: Arc::new(allowed_repos),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -42,24 +42,12 @@ pub(crate) async fn hook(
|
|||||||
debug!("REQ: {:?}", payload);
|
debug!("REQ: {:?}", payload);
|
||||||
match payload {
|
match payload {
|
||||||
HookRequest::Push(webhook_payload) => {
|
HookRequest::Push(webhook_payload) => {
|
||||||
let kubernetes_client: kube::Client = kube::Client::try_default()
|
let kubernetes_client: Client = Client::try_default()
|
||||||
.await
|
.await
|
||||||
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
.expect("Set KUBECONFIG to a valid kubernetes config.");
|
||||||
|
|
||||||
let gitea_api_root = std::env::var("WEBHOOK_BRIDGE_API_ROOT");
|
let gitea_api_root = std::env::var("WEBHOOK_BRIDGE_API_ROOT")?;
|
||||||
let gitea_api_token = std::env::var("WEBHOOK_BRIDGE_OAUTH_TOKEN");
|
let gitea_api_token = std::env::var("WEBHOOK_BRIDGE_OAUTH_TOKEN")?;
|
||||||
let (gitea_api_root, gitea_api_token) = match (gitea_api_root, gitea_api_token) {
|
|
||||||
(Ok(r), Ok(t)) => (r, t),
|
|
||||||
_ => {
|
|
||||||
return (
|
|
||||||
StatusCode::OK,
|
|
||||||
Json(HookResponse {
|
|
||||||
ok: true,
|
|
||||||
message: None,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let gitea = GiteaClient::new(gitea_api_root, gitea_api_token);
|
let gitea = GiteaClient::new(gitea_api_root, gitea_api_token);
|
||||||
|
|
||||||
let push_result = handle_push(
|
let push_result = handle_push(
|
||||||
|
|||||||
Reference in New Issue
Block a user