Migrate Structure

This commit is contained in:
Marcin Grzejszczak
2023-09-08 16:55:46 +02:00
committed by spencergibb
parent 46e529d181
commit ece95fd2c7
8 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,80 @@
image::https://circleci.com/gh/spring-cloud/spring-cloud-config/tree/master.svg?style=svg["CircleCI", link="https://circleci.com/gh/spring-cloud/spring-cloud-config/tree/master"]
image::https://codecov.io/gh/spring-cloud/spring-cloud-config/branch/master/graph/badge.svg["Codecov", link="https://codecov.io/gh/spring-cloud/spring-cloud-config/branch/master"]
image::https://api.codacy.com/project/badge/Grade/f064024a072c477e97dca6ed5a70fccd?branch=master["Codacy code quality", link="https://www.codacy.com/app/Spring-Cloud/spring-cloud-config?branch=master&utm_source=github.com&utm_medium=referral&utm_content=spring-cloud/spring-cloud-config&utm_campaign=Badge_Grade"]
include::intro.adoc[]
== Features
=== Spring Cloud Config Server
Spring Cloud Config Server offers the following benefits:
* HTTP resource-based API for external configuration (name-value pairs or equivalent YAML content)
* Encrypt and decrypt property values (symmetric or asymmetric)
* Embeddable easily in a Spring Boot application using `@EnableConfigServer`
=== Spring Cloud Config Client
Specifically for Spring applications, Spring Cloud Config Client lets you:
* Bind to the Config Server and initialize Spring `Environment` with remote property sources.
* Encrypt and decrypt property values (symmetric or asymmetric).
* `@RefreshScope` for Spring `@Beans` that want to be re-initialized when configuration changes.
* Use management endpoints:
** `/env` for updating `Environment` and rebinding `@ConfigurationProperties` and log levels.
** `/refresh` for refreshing the `@RefreshScope` beans.
** `/restart` for restarting the Spring context (disabled by default).
** `/pause` and `/resume` for calling the `Lifecycle` methods (`stop()` and `start()` on the `ApplicationContext`).
* Bootstrap application context: a parent context for the main application that can be trained to do anything (by default, it binds to the Config Server and decrypts property values).
== Quick Start
include::quickstart.adoc[]
=== Sample Application
You can find a sample application https://github.com/spring-cloud/spring-cloud-config/tree/master/spring-cloud-config-sample[here].
It is a Spring Boot application, so you can run it by using the usual mechanisms (for instance, `mvn spring-boot:run`).
When it runs, it looks for the config server on `http://localhost:8888` (a configurable default), so you can run the server as well to see it all working together.
The sample has a test case where the config server is also started in the same JVM (with a different port), and the test asserts that an
environment property from the git configuration repo is present.
To change the location of the config server, you can set `spring.cloud.config.uri` in `bootstrap.yml` (or in system properties and other places).
The test case has a `main()` method that runs the server in the same way (watch the logs for its port), so you can run the whole system in one process and play with it (for example, you can run the `main()` method in your IDE).
The `main()` method uses `target/config` for the working directory of the git repository, so you can make local changes there and see them reflected in the running app. The following example shows a session of tinkering with the test case:
----
$ curl localhost:8080/env/sample
mytest
$ vi target/config/mytest.properties
.. change value of "sample", optionally commit
$ curl -X POST localhost:8080/refresh
["sample"]
$ curl localhost:8080/env/sample
sampleValue
----
The refresh endpoint reports that the "sample" property changed.
== Building
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/building.adoc[]
=== JCE
If you get an exception due to "Illegal key size" and you are using Suns JDK, you need to install the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files.
See the following links for more information:
https://www.oracle.com/technetwork/java/javase/downloads/jce-6-download-429243.html[Java 6 JCE]
https://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html[Java 7 JCE]
https://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html[Java 8 JCE]
Extract the JCE files into the `JDK/jre/lib/security` folder for whichever version of JRE/JDK x64/x86 you use.
== Contributing
include::https://raw.githubusercontent.com/spring-cloud/spring-cloud-build/main/docs/modules/ROOT/partials/contributing.adoc[]

View File

@@ -0,0 +1,31 @@
|===
|Name | Default | Description
|spring.cloud.config.allow-override | `+++true+++` | Flag to indicate that {@link #isOverrideSystemProperties() systemPropertiesOverride} can be used. Set to false to prevent users from changing the default accidentally. Default true.
|spring.cloud.config.discovery.enabled | `+++false+++` | Flag to indicate that config server discovery is enabled (config server URL will be looked up via discovery).
|spring.cloud.config.discovery.service-id | `+++configserver+++` | Service id to locate config server.
|spring.cloud.config.enabled | `+++true+++` | Flag to say that remote configuration is enabled. Default true;
|spring.cloud.config.fail-fast | `+++false+++` | Flag to indicate that failure to connect to the server is fatal (default false).
|spring.cloud.config.headers | | Additional headers used to create the client request.
|spring.cloud.config.initialize-on-context-refresh | `+++false+++` | Flag to initialize bootstrap configuration on context refresh event. Default false.
|spring.cloud.config.label | | The label name to use to pull remote configuration properties. The default is set on the server (generally "main" for a git based server).
|spring.cloud.config.media-type | | The Accept header media type to send to config server.
|spring.cloud.config.multiple-uri-strategy | | The strategy to use when call to server fails and there are multiple URLs configured on the uri property (default {@link MultipleUriStrategy#ALWAYS}).
|spring.cloud.config.name | | Name of application used to fetch remote properties.
|spring.cloud.config.override-none | `+++false+++` | Flag to indicate that when {@link #setAllowOverride(boolean) allowOverride} is true, external properties should take lowest priority and should not override any existing property sources (including local config files). Default false. This will only have an effect when using config first bootstrap.
|spring.cloud.config.override-system-properties | `+++true+++` | Flag to indicate that the external properties should override system properties. Default true.
|spring.cloud.config.password | | The password to use (HTTP Basic) when contacting the remote server.
|spring.cloud.config.profile | `+++default+++` | The default profile to use when fetching remote configuration (comma-separated). Default is "default".
|spring.cloud.config.request-connect-timeout | `+++0+++` | timeout on waiting to connect to the Config Server.
|spring.cloud.config.request-read-timeout | `+++0+++` | timeout on waiting to read data from the Config Server.
|spring.cloud.config.retry.initial-interval | `+++1000+++` | Initial retry interval in milliseconds.
|spring.cloud.config.retry.max-attempts | `+++6+++` | Maximum number of attempts.
|spring.cloud.config.retry.max-interval | `+++2000+++` | Maximum interval for backoff.
|spring.cloud.config.retry.multiplier | `+++1.1+++` | Multiplier for next interval.
|spring.cloud.config.send-state | `+++true+++` | Flag to indicate whether to send state. Default true.
|spring.cloud.config.tls | | TLS properties.
|spring.cloud.config.token | | Security Token passed thru to underlying environment repository.
|spring.cloud.config.uri | `+++[http://localhost:8888]+++` | The URI of the remote server (default http://localhost:8888).
|spring.cloud.config.username | | The username to use (HTTP Basic) when contacting the remote server.
|===

View File

@@ -0,0 +1,8 @@
:root-target: ../../../target/
[[observability]]
== Observability metadata
include::{root-target}_metrics.adoc[]
include::{root-target}_spans.adoc[]

View File

@@ -0,0 +1 @@
include::spring-cloud-config.adoc[]

View File

@@ -0,0 +1,6 @@
Spring Cloud Config provides server-side and client-side support for externalized configuration in a distributed system. With the Config Server, you have a central place to manage external properties for applications across all environments.
The concepts on both client and server map identically to the Spring `Environment` and `PropertySource` abstractions, so they fit very well with Spring applications but can be used with any application running in any language.
As an application moves through the deployment pipeline from dev to test and into production, you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate.
The default implementation of the server storage backend uses git, so it easily supports labelled versions of configuration environments as well as being accessible to a wide range of tooling for managing the content.
It is easy to add alternative implementations and plug them in with Spring configuration.

View File

@@ -0,0 +1,193 @@
This quick start walks through using both the server and the client of Spring Cloud Config Server.
First, start the server, as follows:
----
$ cd spring-cloud-config-server
$ ../mvnw spring-boot:run
----
The server is a Spring Boot application, so you can run it from your IDE if you prefer to do so (the main class is `ConfigServerApplication`).
Next try out a client, as follows:
----
$ curl localhost:8888/foo/development
{
"name": "foo",
"profiles": [
"development"
]
....
"propertySources": [
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo-development.properties",
"source": {
"bar": "spam",
"foo": "from foo development"
}
},
{
"name": "https://github.com/spring-cloud-samples/config-repo/foo.properties",
"source": {
"foo": "from foo props",
"democonfigclient.message": "hello spring io"
}
},
....
----
The default strategy for locating property sources is to clone a git repository (at `spring.cloud.config.server.git.uri`) and use it to initialize a mini `SpringApplication`.
The mini-application's `Environment` is used to enumerate property sources and publish them at a JSON endpoint.
The HTTP service has resources in the following form:
----
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
----
For example:
----
curl localhost:8888/foo/development
curl localhost:8888/foo/development/master
curl localhost:8888/foo/development,db/master
curl localhost:8888/foo-development.yml
curl localhost:8888/foo-db.properties
curl localhost:8888/master/foo-db.properties
----
where `application` is injected as the `spring.config.name` in the `SpringApplication` (what is normally `application` in a regular Spring Boot app), `profile` is an active profile (or comma-separated list of properties), and `label` is an optional git label (defaults to `master`.)
Spring Cloud Config Server pulls configuration for remote clients from various sources. The following example gets configuration from a git repository (which must be provided), as shown in the following example:
[source,yaml]
----
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
----
Other sources are any JDBC compatible database, Subversion, Hashicorp Vault, Credhub and local filesystems.
=== Client Side Usage
To use these features in an application, you can build it as a Spring Boot application that depends on spring-cloud-config-client (for an example, see the test cases for the config-client or the sample application).
The most convenient way to add the dependency is with a Spring Boot starter `org.springframework.cloud:spring-cloud-starter-config`.
There is also a parent pom and BOM (`spring-cloud-starter-parent`) for Maven users and a Spring IO version management properties file for Gradle and Spring CLI users. The following example shows a typical Maven configuration:
[source,xml,indent=0]
.pom.xml
----
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>{spring-boot-docs-version}</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>{spring-cloud-version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- repositories also needed for snapshots and milestones -->
----
Now you can create a standard Spring Boot application, such as the following HTTP server:
----
@SpringBootApplication
@RestController
public class Application {
@RequestMapping("/")
public String home() {
return "Hello World!";
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
----
When this HTTP server runs, it picks up the external configuration from the default local config server (if it is running) on port 8888.
To modify the startup behavior, you can change the location of the config server by using `application.properties` as shown in the following example:
----
spring.config.import=optional:configserver:http://myconfigserver.com
----
By default, if no application name is set, `application` will be used. To modify the name, the following property can be added to the `application.properties` file:
----
spring.application.name: myapp
----
NOTE: When setting the property `${spring.application.name}` do not prefix your app name with the reserved word `application-` to prevent issues resolving the correct property source.
The Config Server properties show up in the `/env` endpoint as a high-priority property source, as shown in the following example.
----
$ curl localhost:8080/env
{
"activeProfiles": [],
{
"name": "servletContextInitParams",
"properties": {}
},
{
"name": "configserver:https://github.com/spring-cloud-samples/config-repo/foo.properties",
"properties": {
"foo": {
"value": "bar",
"origin": "Config Server https://github.com/spring-cloud-samples/config-repo/foo.properties:2:12"
}
}
},
...
}
----
A property source called `configserver:<URL of remote repository>/<file name>` contains the `foo` property with a value of `bar`.
NOTE: The URL in the property source name is the git repository, not the config server URL.
WARNING: If you use Spring Cloud Config Client, you need to set the `spring.config.import` property in order to bind to Config Server. You can read more about it https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#config-data-import[in the Spring Cloud Config Reference Guide].

View File

@@ -0,0 +1,49 @@
Spring Cloud Config provides server and client-side support for externalized configuration in a distributed system. With the Config Server you have a central place to manage external properties for applications across all environments. The concepts on both client and server map identically to the Spring `Environment` and `PropertySource` abstractions, so they fit very well with Spring applications, but can be used with any application running in any language. As an application moves through the deployment pipeline from dev to test and into production you can manage the configuration between those environments and be certain that applications have everything they need to run when they migrate. The default implementation of the server storage backend uses git so it easily supports labelled versions of configuration environments, as well as being accessible to a wide range of tooling for managing the content. It is easy to add alternative implementations and plug them in with Spring configuration.
## Features
Spring Cloud Config Server features:
* HTTP, resource-based API for external configuration (name-value pairs, or equivalent YAML content)
* Encrypt and decrypt property values (symmetric or asymmetric)
* Embeddable easily in a Spring Boot application using `@EnableConfigServer`
Config Client features (for Spring applications):
* Bind to the Config Server and initialize Spring `Environment` with remote property sources
* Encrypt and decrypt property values (symmetric or asymmetric)
## Getting Started
As long as Spring Boot Actuator and Spring Config Client are on the
classpath any Spring Boot application will try to contact a config
server on `http://localhost:8888`, the default value of
`spring.cloud.config.uri`. If you would like to change this default,
you can set `spring.cloud.config.uri` in `bootstrap.[yml | properties]`
or via system properties or environment variables.
```java
@Configuration
@EnableAutoConfiguration
@RestController
public class Application {
@Value("${config.name}")
String name = "World";
@RequestMapping("/")
public String home() {
return "Hello " + name;
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
```
The value of `config.name` in the sample (or any other values you bind to in the normal Spring Boot way) can come from local configuration or from the remote Config Server. The Config Server will take precedence by default. To see this look at the `/env` endpoint in the application and see the `configServer` property sources.
To run your own server use the `spring-cloud-config-server` dependency and `@EnableConfigServer`. If you set `spring.config.name=configserver` the app will run on port 8888 and serve data from a sample repository. You need a `spring.cloud.config.server.git.uri` to locate the configuration data for your own needs (by default it is the location of a git repository, and can be a local `file:..` URL).

File diff suppressed because it is too large Load Diff