Set max_prepared_transactions in TestContainers PostgreSQLContainer - testcontainers

It's possible to set max_prepared_transactions in PostgreSQLContainer?

For the moment i resolved by build new docker image of postgres, such as below:
FROM postgres:10
RUN sed -ri "s!^#?(max_prepared_transactions)\s*=.*!\1 = 110!"
/usr/share/postgresql/postgresql.conf.sample
source

Related

How to build an image from Dockerfile using Earthly target?

I would like to build and image from Dockerfile using Earthly.
You might be wondering why do I want that, because I can describe images right inside of Earthfile, but I have 2 reasons for using external Dockerfile:
ADD command (which I need to download file by URL) is not supported by Earthly yet
I would like to use a heredoc syntax for embedding file's content into container right from Dockerfile. This requires # syntax=docker/dockerfile:1.4, which is again not available in Earthfile
So, here is what I tried to do.
My approximate Dockerfile looks like:
# syntax=docker/dockerfile:1.4
FROM gcr.io/distroless/java17:nonroot
WORKDIR /opt/app
ADD --chown=nonroot https://github.com/microsoft/ApplicationInsights-Java/releases/download/3.4.7/applicationinsights-agent-3.4.7.jar agent.jar
COPY <<EOF /opt/app/applicationinsights.json
{
"instrumentation": {}
}
EOF
And this is how I try to build it with Earthly:
base-image:
FROM earthly/dind:alpine
WORKDIR /build
ENV DOCKER_BUILDKIT=1 # <---- required to support heredoc syntax
COPY distroless-runtime-17.Dockerfile Dockerfile
WITH DOCKER --allow-privileged
RUN docker build . -t base-17-image
END
While the WITH DOCKER RUN part gets executed successfully, I do not know how to use the result of base-image target in other targets to package my app using the resulting base image. The FROM base-17-image just fails as if it does not exist (and this tag really does not exist - docker run base-17-image fails with the same reason).
It turned out to be very easy and natively supported:
The whole recipe is just 2 lines of code:
base-image:
FROM DOCKERFILE -f distroless-runtime-17.Dockerfile .
and the result can of the above step can be reused to package your application as: FROM +base-image

Janusgraph enable ConfiguredGraphFactory in test container

I am using test container with Janusgraph, but I need to use ConfiguredGraphFactory in my test. How to enable it in test container? This is how I am starting the test container:
GenericContainer<JanusGraph> janus = new JanusGraph()
.withNetwork(network)
.withExposedPorts(JANUS_PORT)
.waitingFor(Wait.forListeningPort())
.withStartupTimeout(Duration.ofMinutes(5))
.withEnv("janusgraph.storage.backend", "cql")
.withEnv("janusgraph.storage.hostname", storageName)
.withEnv("janusgraph.index.search.backend", "elasticsearch")
.withEnv("janusgraph.index.search.hostname", indexName)
.withEnv("janusgraph.schema.default", "tp3");
I was trying to add .withEnv("janusgraph.graph.graphname"."org.janusgraph.core.ConfiguredGraphFactory") but it doesn't work (image name: janusgraph/janusgraph:0.5.3).
The example yaml and properties files for trying ConfiguredGraphFactory can be found at:
conf/gremlin-server/gremlin-server-configuration.yaml
conf/janusgraph-cql-configurationgraph.properties
It is described in the janusgraph-docker project that you can define gremlin.* and janusgraph.* environment variables in your Dockerfile to override the default configs. Your approach with GenericContainer.withEnv() should be fine too.
From looking at this JanusGraph PR, I think this approach should work:
.withEnv("gremlin.graph"."org.janusgraph.core.ConfiguredGraphFactory")
However, I have no experience with JanusGraph and I think this is not a Testcontainers-specific question. This means you can conceptually configure it for Testcontainers the same way to would configure it for a Docker container with the Docker CLI.

How can I override ddev's php-fpm.conf or pool.d/www.conf?

There is no obvious way to override some php-fpm configuration in DDEV-Local's web container. Although it's easy to provide custom PHP configuration it's not as obvious how one would configure the php-fpm process itself.
In my case I want to change the security.limit-extensions value in pool.d/www.conf
There are two ways to do this. I'll create two separate answers to explain how.
The first technique is to create a custom Dockerfile (docs) which edits the www.conf (or any other file). You can also use the Dockerfile ADD command to add a complete file and override them.
In the case of this specific problem, we'll create a .ddev/web-build/Dockerfile with these contents:
# You can copy this Dockerfile.example to Dockerfile to add configuration
# or packages or anything else to your webimage
ARG BASE_IMAGE
FROM $BASE_IMAGE
ENV PHP_VERSION=7.4
RUN echo "security.limit_extensions = .php .html" >> /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
After you ddev start you'll have the new configuration.
Instead of the RUN echo approach that just appends to the file, given here for simplicity, you could RUN a sed/awk/perl statement to change the file in place.
And alternatively you could put the version of the www.conf that you want into the .ddev/web-build directory and
COPY www.conf /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
The second way to approach this is to use a custom docker-compose.*.yaml file (docs.
Here you'll copy the desired www.conf (or any other file) into your project's .ddev directory and then mount it into the web container on top of the previously provided one. For this specific example, you can copy the www.conf into the .ddev folder by cd .ddev && docker cp ddev-<projectname>-web:/etc/php/7.4/fpm/pool.d/www.conf . and edit it as you need to (edit it with "security.limit_extensions = .php .html").
Then a custom .ddev/docker-compose.*.yaml file like this can mount it into the proper directory (mine is called docker-compose.wwwconf.yaml):
version: "3.6"
services:
web:
volumes:
- "./www.conf:/etc/php/7.4/fpm/pool.d/www.conf"
if you are using docker-compose, mount zz-docker.conf where your customized configure placed, sample as bellow
php:
build: ./php
image: ctc/php:latest
container_name: ctc-php
expose:
- 9000
volumes:
- ./html:/var/www/html
- ./php/log:/var/log/php-fpm
- ./php/php-fpm.d/zz-docker.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
networks:
- koogua
restart: always
zz-docker.conf looks like bellow:
[global]
daemonize = no
[www]
listen = 9000
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.max_requests = 500
note: mount www.conf will cause error

How to get the image digest by image name & tag

I am trying to get the digest of a docker image which I have built and pushed to a private repository.
How can I get the digest by image-name:tag using a bash command?
I tried this command:
docker images --format "{{.Digest}}" --filter reference=${registry}/${image-name}:${tag}
but it doesn't return what I would like to get, e.g. just the digest of the ${registry}/${image-name}:${tag} image.
Any help with this?
This solved the issue:
docker inspect --format='{{index .RepoDigests 0}}' $IMAGE

Jaeger Service not shown in Jaeger UI

I installed the jaeger all in one in Docker with:
docker run --rm --name jaeger -p 5775:5775/udp -p 6831:6831/udp -p 6832:6832/udp -p 5778:5778 -p 16686:16686 -p 14267:14267 -p 14268:14268 -p 9411:9411 jaegertracing/all-in-one:1.7
And below is the sample code on how I initialize the tracer and spans.
I get the logs in my console but it does not reflect in my Jaeger UI.
Could anyone please help me with this?
logging = new LoggingReporter();
SamplerConfiguration sampler = new SamplerConfiguration();
sampler.withType("const");
sampler.withParam(1);
ReporterConfiguration reporter = new ReporterConfiguration();
reporter.withLogSpans(true);
reporter.withSender(sender);
tracer = Configuration.fromEnv("sample_jaeger").withSampler(sampler).withReporter(reporter).getTracer();
Scope scope = tracer.buildSpan("parent-span").startActive(true);
Tags.SAMPLING_PRIORITY.set(scope.span(), 1);
scope.span().setTag("this-is-test", "YUP");
logging.report((JaegerSpan) scope.span());
Are you closing the tracer and the scope? If you are using a version before 0.32.0, you should manually call tracer.close() before your process terminates, otherwise the spans in the buffer might not get dispatched.
As for the scope, it's common to wrap it in a try-with-resources statement:
try (Scope scope = tracer.buildSpan("parent-span").startActive(true)) {
Tags.SAMPLING_PRIORITY.set(scope.span(), 1);
scope.span().setTag("this-is-test", "YUP");
logging.report((JaegerSpan) scope.span());
}
You might also want to check the OpenTracing tutorial at https://github.com/yurishkuro/opentracing-tutorial or the Katacoda-based version at https://www.katacoda.com/courses/opentracing
-- EDIT
and is deployed on a different hostname and port
Then you do need to tell the tracer where to send the traces. Either export the JAEGER_ENDPOINT environment variable, pointing to a collector endpoint, or set JAEGER_AGENT_HOST/JAEGER_AGENT_PORT, with the location of the agent. You can check the available environment variables for your client on the following URL: https://www.jaegertracing.io/docs/1.7/client-features/

Resources