diff --git a/services/.env b/services/.env --- a/services/.env +++ b/services/.env @@ -2,4 +2,5 @@ COMM_SERVICES_PORT_BACKUP=50052 COMM_SERVICES_PORT_BLOB=50053 COMM_SERVICES_PORT_IDENTITY=50054 +COMM_SERVICES_PORT_FEATURE_FLAGS=50055 COMM_TEST_SERVICES=0 diff --git a/services/docker-compose.yml b/services/docker-compose.yml --- a/services/docker-compose.yml +++ b/services/docker-compose.yml @@ -65,6 +65,18 @@ image: commapp/identity-server:0.1 ports: - '${COMM_SERVICES_PORT_IDENTITY}:50051' + feature-flags-server: + depends_on: + - localstack + build: + dockerfile: services/feature-flags/Dockerfile + context: ../ + image: commapp/feature-flags:0.1 + ports: + - '${COMM_SERVICES_PORT_FEATURE_FLAGS}:50051' + volumes: + - $HOME/.aws/config:/home/comm/.aws/config:ro + - $HOME/.aws/credentials:/home/comm/.aws/credentials:ro # localstack localstack: image: localstack/localstack diff --git a/services/feature-flags/Dockerfile b/services/feature-flags/Dockerfile new file mode 100644 --- /dev/null +++ b/services/feature-flags/Dockerfile @@ -0,0 +1,44 @@ +FROM commapp/services-base:1.3.2 as builder + +ENV PATH=/root/.cargo/bin:$PATH + +# Install Curl +RUN apt-get update \ + && DEBIAN_FRONTEND=noninteractive apt-get install -y curl \ + && rm -rf /var/lib/apt/lists/* + +# Install Rust +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y + +RUN mkdir -p /home/comm/app/feature-flags +WORKDIR /home/comm/app/feature-flags +RUN cargo init --bin + +# Cache build dependencies in a new layer +COPY services/blob/Cargo.toml services/blob/Cargo.lock ./ +COPY services/comm-services-lib ../comm-services-lib +RUN cargo build --release + +# Copy actual application sources +COPY services/feature-flags . + +# Remove the previously-built binary so that only the application itself is +# rebuilt +RUN rm -f ./target/release/deps/feature-flags* +RUN cargo build --release + +# Runner stage +FROM commapp/services-base:1.3.2 as runner + +# Create a new user comm and use it to run subsequent commands +RUN useradd -m comm +USER comm + +# Only copy built binary from builder stage +WORKDIR /home/comm/app/feature-flags +COPY --from=builder /home/comm/app/feature-flags/target/release/feature-flags . + +ARG COMM_SERVICES_SANDBOX +ENV COMM_SERVICES_SANDBOX=${COMM_SERVICES_SANDBOX} + +CMD ./feature-flags diff --git a/services/feature-flags/src/config.rs b/services/feature-flags/src/config.rs --- a/services/feature-flags/src/config.rs +++ b/services/feature-flags/src/config.rs @@ -5,7 +5,7 @@ use tracing::info; use crate::constants::{ - AWS_REGION, DEFAULT_LOCALSTACK_URL, HTTP_SERVER_DEFAULT_PORT, + AWS_REGION, DEFAULT_LOCALSTACK_URL, HTTP_SERVER_DEFAULT_PORT, SANDBOX_ENV_VAR, }; #[derive(Parser)] @@ -13,6 +13,7 @@ pub struct AppConfig { /// Run the service in sandbox #[arg(long = "sandbox", default_value_t = false)] + #[arg(env = SANDBOX_ENV_VAR)] #[arg(value_parser = FalseyValueParser::new())] pub is_sandbox: bool, /// AWS Localstack service URL, applicable in sandbox mode diff --git a/services/feature-flags/src/constants.rs b/services/feature-flags/src/constants.rs --- a/services/feature-flags/src/constants.rs +++ b/services/feature-flags/src/constants.rs @@ -3,6 +3,7 @@ pub const LOG_LEVEL_ENV_VAR: &str = tracing_subscriber::filter::EnvFilter::DEFAULT_ENV; pub const HTTP_SERVER_DEFAULT_PORT: u16 = 50051; +pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX"; // The configuration of feature flags is stored in a table in DynamoDB. // Each row is identified by a compound primary key consisting of diff --git a/services/feature-flags/src/service.rs b/services/feature-flags/src/service.rs --- a/services/feature-flags/src/service.rs +++ b/services/feature-flags/src/service.rs @@ -26,7 +26,7 @@ .route(web::get().to(Self::features_handler)), ) }) - .bind(("localhost", CONFIG.http_port))? + .bind(("0.0.0.0", CONFIG.http_port))? .run() .await } diff --git a/services/package.json b/services/package.json --- a/services/package.json +++ b/services/package.json @@ -14,6 +14,8 @@ "build-blob-base": "./scripts/build_base_image.sh && docker-compose build blob-base", "run-blob-service": "./scripts/run_server_image.sh blob", "run-blob-service-in-sandbox": "COMM_SERVICES_SANDBOX=1 ./scripts/run_server_image.sh blob", + "run-feature-flags-service": "./scripts/run_server_image.sh feature-flags", + "run-feature-flags-service-in-sandbox": "COMM_SERVICES_SANDBOX=1 ./scripts/run_server_image.sh feature-flags", "run-all-services": "./scripts/run_all_services.sh", "run-unit-tests": "./scripts/run_unit_tests.sh", "run-integration-tests": "./scripts/run_integration_tests.sh", diff --git a/services/scripts/run_server_image.sh b/services/scripts/run_server_image.sh --- a/services/scripts/run_server_image.sh +++ b/services/scripts/run_server_image.sh @@ -24,6 +24,10 @@ if [[ -n "$2" ]]; then export COMM_SERVICES_PORT_BLOB=$2 fi +elif [[ "$SERVICE" == "feature-flags" ]]; then + if [[ -n "$2" ]]; then + export COMM_SERVICES_PORT_FEATURE_FLAGS=$2 + fi else echo "No such service ${SERVICE}, aborting" exit 1