Skip to content

Commit

Permalink
feat: add version tag to our deployment
Browse files Browse the repository at this point in the history
This goal is to enable Datadog to track versions, deployments, and to
be able to automatically detected regressions or new bug associated with
a version.
  • Loading branch information
Kazy committed Jan 19, 2024
1 parent ab179c3 commit 2dba345
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Expand Up @@ -384,7 +384,7 @@ jobs:
- run:
name: Make and push images
command: |
PUSH=true SHUTTLE_ENV=<< parameters.shuttle-env >> PLATFORMS=linux/amd64 TAG=$TAG make images
PUSH=true SHUTTLE_SERVICE_VERSION=$TAG SHUTTLE_ENV=<< parameters.shuttle-env >> PLATFORMS=linux/amd64 TAG=$TAG make images
- save-buildx-cache
deploy-images:
executor: machine-ubuntu
Expand Down
14 changes: 14 additions & 0 deletions Containerfile
Expand Up @@ -63,6 +63,8 @@ RUN apt update && apt install -y curl ca-certificates; rm -rf /var/lib/apt/lists

#### AUTH
FROM bookworm-20230904-slim-plus AS shuttle-auth
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-auth /usr/local/bin
ENTRYPOINT ["/usr/local/bin/shuttle-auth"]
Expand All @@ -72,6 +74,8 @@ FROM shuttle-auth AS shuttle-auth-dev
#### BUILDER
ARG RUSTUP_TOOLCHAIN
FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-bookworm AS shuttle-builder
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
ARG prepare_args
COPY builder/prepare.sh /prepare.sh
Expand All @@ -84,6 +88,8 @@ FROM shuttle-builder AS shuttle-builder-dev
#### DEPLOYER
ARG RUSTUP_TOOLCHAIN
FROM docker.io/library/rust:${RUSTUP_TOOLCHAIN}-bookworm AS shuttle-deployer
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
ARG prepare_args
# Fixes some dependencies compiled with incompatible versions of rustc
Expand Down Expand Up @@ -115,6 +121,8 @@ COPY --from=chef-planner /build /usr/src/shuttle/

#### GATEWAY
FROM bookworm-20230904-slim-plus AS shuttle-gateway
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
COPY gateway/ulid0.so /usr/lib/
COPY gateway/ulid0_aarch64.so /usr/lib/
Expand All @@ -132,6 +140,8 @@ COPY --from=chef-planner /build/*.pem /usr/src/shuttle/

#### LOGGER
FROM docker.io/library/debian:bookworm-20230904-slim AS shuttle-logger
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-logger /usr/local/bin
ENTRYPOINT ["/usr/local/bin/shuttle-logger"]
Expand All @@ -141,6 +151,8 @@ FROM shuttle-logger AS shuttle-logger-dev
#### PROVISIONER
ARG RUSTUP_TOOLCHAIN
FROM bookworm-20230904-slim-plus AS shuttle-provisioner
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-provisioner /usr/local/bin
ENTRYPOINT ["/usr/local/bin/shuttle-provisioner"]
Expand All @@ -149,6 +161,8 @@ FROM shuttle-provisioner AS shuttle-provisioner-dev

#### RESOURCE RECORDER
FROM docker.io/library/debian:bookworm-20230904-slim AS shuttle-resource-recorder
ARG SHUTTLE_SERVICE_VERSION
ENV SHUTTLE_SERVICE_VERSION=${SHUTTLE_SERVICE_VERSION}
ARG CARGO_PROFILE
COPY --from=chef-builder /build/target/${CARGO_PROFILE}/shuttle-resource-recorder /usr/local/bin
ENTRYPOINT ["/usr/local/bin/shuttle-resource-recorder"]
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Expand Up @@ -143,7 +143,8 @@ DOCKER_COMPOSE_ENV=\
USE_TLS=$(USE_TLS)\
COMPOSE_PROFILES=$(COMPOSE_PROFILES)\
DOCKER_SOCK=$(DOCKER_SOCK)\
SHUTTLE_ENV=$(SHUTTLE_ENV)
SHUTTLE_ENV=$(SHUTTLE_ENV)\
SHUTTLE_SERVICE_VERSION=$(SHUTTLE_SERVICE_VERSION)

.PHONY: clean cargo-clean images the-shuttle-images shuttle-% postgres panamax otel deploy test docker-compose.rendered.yml up down

Expand All @@ -165,6 +166,7 @@ shuttle-%:
--build-arg crate=$(@) \
--build-arg prepare_args=$(PREPARE_ARGS) \
--build-arg SHUTTLE_ENV=$(SHUTTLE_ENV) \
--build-arg SHUTTLE_SERVICE_VERSION=$(SHUTTLE_SERVICE_VERSION) \
--build-arg RUSTUP_TOOLCHAIN=$(RUSTUP_TOOLCHAIN) \
--build-arg CARGO_PROFILE=$(CARGO_PROFILE) \
--tag $(CONTAINER_REGISTRY)/$(*):$(COMMIT_SHA) \
Expand Down
21 changes: 13 additions & 8 deletions common/src/backends/tracing.rs
Expand Up @@ -39,28 +39,33 @@ where
// The OTLP_ADDRESS env var is useful for setting a localhost address when running deployer locally.
let otlp_address = std::env::var("OTLP_ADDRESS").unwrap_or(OTLP_ADDRESS.into());

let resources = {
let mut resources = vec![
KeyValue::new("service.name", backend.to_string().to_lowercase()),
KeyValue::new("deployment.environment", shuttle_env.clone()),
];
if let Ok(service_version) = std::env::var("SHUTTLE_SERVICE_VERSION") {
resources.push(KeyValue::new("service.version", service_version));
}
resources
};

let tracer = opentelemetry_otlp::new_pipeline()
.tracing()
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
.with_endpoint(otlp_address.clone()),
)
.with_trace_config(trace::config().with_resource(Resource::new(vec![
KeyValue::new("service.name", backend.to_string().to_lowercase()),
KeyValue::new("deployment.environment", shuttle_env.clone()),
])))
.with_trace_config(trace::config().with_resource(Resource::new(resources.clone())))
.install_batch(Tokio)
.unwrap();

let otel_layer = tracing_opentelemetry::layer().with_tracer(tracer);

let logs = opentelemetry_otlp::new_pipeline()
.logging()
.with_log_config(Config::default().with_resource(Resource::new(vec![
KeyValue::new("service.name", backend.to_string().to_lowercase()),
KeyValue::new("deployment.environment", shuttle_env.clone()),
])))
.with_log_config(Config::default().with_resource(Resource::new(resources.clone())))
.with_exporter(
opentelemetry_otlp::new_exporter()
.tonic()
Expand Down

0 comments on commit 2dba345

Please sign in to comment.