Skip to content

Commit e3fc05b

Browse files
feat: publish flex docker image (#5)
* feat: publish flex docker image * flex-build-push.yml: rename docker image * Add healthcheck to Dockerfile.flex * Optionally read options from environment * postmaster/flex/Main: Fix reading from environment * postmaster/flex/Main: Fix reading from environment * postmaster/flex/Main: Allow selection of destination port * .github/workflows/flex-build-push: remove merge group and multi platform support
1 parent c746bae commit e3fc05b

File tree

3 files changed

+95
-7
lines changed

3 files changed

+95
-7
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
name: Build & Push Flex Docker Container
3+
4+
on:
5+
push:
6+
branches: [main]
7+
tags: ["v*.*.*"]
8+
pull_request:
9+
types: [opened, synchronize, reopened]
10+
11+
permissions:
12+
contents: read
13+
14+
env:
15+
REGISTRY: ghcr.io
16+
17+
jobs:
18+
build-push-flex:
19+
runs-on: [ubuntu-latest]
20+
permissions:
21+
contents: write
22+
packages: write
23+
pull-requests: write
24+
steps:
25+
- uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
26+
id: metadata
27+
env:
28+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
29+
with:
30+
images: ${{ env.REGISTRY }}/${{ github.repository }}-flex
31+
# Generate Docker tags based on the following events/attributes
32+
tags: |
33+
type=raw,value=latest,enable={{is_default_branch}}
34+
type=ref,event=pr
35+
type=semver,pattern={{raw}}
36+
type=semver,pattern={{version}}
37+
type=semver,pattern={{major}}.{{minor}}
38+
type=semver,pattern={{major}}
39+
- uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
40+
- uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
41+
with:
42+
registry: ${{ env.REGISTRY }}
43+
username: ${{ github.actor }}
44+
password: ${{ secrets.GITHUB_TOKEN }}
45+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
46+
with:
47+
persist-credentials: false
48+
submodules: true
49+
- uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
50+
with:
51+
file: Dockerfile.flex
52+
tags: ${{ steps.metadata.outputs.tags }}
53+
labels: ${{ steps.metadata.outputs.labels }}
54+
annotations: ${{ steps.metadata.outputs.annotations }}
55+
sbom: true
56+
provenance: true
57+
cache-from: type=gha
58+
cache-to: type=gha,mode=max

Dockerfile.flex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,21 @@ COPY . /workspace
1010
RUN cmake --preset flex \
1111
&& cmake --build --preset flex
1212

13+
RUN apt-get update && apt-get install -y --no-install-recommends net-tools
14+
1315
FROM scratch
1416

17+
HEALTHCHECK --interval=5s --retries=100 CMD netstat -ltn | grep -c ":1234"; if [ 0 != $? ]; then exit 1; fi;
18+
1519
WORKDIR /flex
1620
COPY --from=builder /workspace/build/flex/postmaster/flex/postmaster.flex /flex/
1721
COPY --from=builder /lib/x86_64-linux-gnu/libc.so.6 /lib/x86_64-linux-gnu/libc.so.6
22+
COPY --from=builder /bin/sh /bin/sh
23+
COPY --from=builder /usr/bin/netstat /usr/bin/netstat
24+
COPY --from=builder /usr/bin/grep /usr/bin/grep
25+
COPY --from=builder /lib/x86_64-linux-gnu/libselinux.so.1 /lib/x86_64-linux-gnu/libselinux.so.1
26+
COPY --from=builder /lib/x86_64-linux-gnu/libpcre2-8.so.0 /lib/x86_64-linux-gnu/libpcre2-8.so.0
27+
COPY --from=builder /lib64/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
1828

1929
ENTRYPOINT ["/flex/postmaster.flex"]
2030
CMD ["--help"]

postmaster/flex/Main.cpp

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
#include "services/network_instantiations/NetworkAdapter.hpp"
1212
#include "services/tracer/GlobalTracer.hpp"
1313
#include "services/tracer/TracerOnIoOutputInfrastructure.hpp"
14+
#include <cstdlib>
15+
16+
std::string Env(const char* name)
17+
{
18+
auto result = std::getenv(name);
19+
if (result != nullptr)
20+
return result;
21+
else
22+
return "";
23+
}
1424

1525
int main(int argc, const char* argv[], const char* env[])
1626
{
@@ -24,25 +34,35 @@ int main(int argc, const char* argv[], const char* env[])
2434

2535
try
2636
{
27-
parser.ParseCLI(argc, argv);
37+
std::string firmwareArg = Env("POSTMASTER_FIRMWARE");
38+
std::string urlArg = Env("POSTMASTER_IP");
39+
std::string passwordArg = Env("POSTMASTER_PASSWORD");
40+
41+
if (firmwareArg.empty() && urlArg.empty())
42+
{
43+
parser.ParseCLI(argc, argv);
44+
firmwareArg = args::get(firmwareArgument);
45+
urlArg = args::get(urlArgument);
46+
passwordArg = args::get(passwordArgument);
47+
}
2848

2949
static hal::TimerServiceGeneric timerService;
3050
static hal::SynchronousRandomDataGeneratorGeneric randomDataGenerator;
3151
static main_::TracerOnIoOutputInfrastructure tracer;
3252
static main_::NetworkAdapter network;
3353
static hal::FileSystemGeneric fileSystem;
3454

35-
static auto firmware = firmwareArgument ? fileSystem.ReadBinaryFile(args::get(firmwareArgument)) : std::vector<uint8_t>{};
55+
static auto firmware = !firmwareArg.empty() ? fileSystem.ReadBinaryFile(firmwareArg) : std::vector<uint8_t>{};
3656

3757
static services::HttpClientConnectorWithNameResolverImpl<> connector(network.ConnectionFactoryWithNameResolver());
38-
static infra::BoundedString::WithStorage<512> httpUrl{ args::get(urlArgument) };
39-
static infra::BoundedString::WithStorage<512> webSocketUrl{ args::get(urlArgument) };
40-
static application::EchoWebSocketClientFactory webSocketFactory(webSocketUrl, 80, network.ConnectionFactory(), tracer.tracer);
58+
static infra::BoundedString::WithStorage<512> httpUrl{ urlArg };
59+
static infra::BoundedString::WithStorage<512> webSocketUrl{ urlArg };
60+
static application::EchoWebSocketClientFactory webSocketFactory(webSocketUrl, services::PortFromUrl(webSocketUrl).ValueOr(80), network.ConnectionFactory(), tracer.tracer);
4161
static services::HttpClientWebSocketInitiation webSocketInitiation(webSocketFactory, connector,
4262
webSocketFactory, randomDataGenerator, services::noAutoConnect);
43-
static application::HttpClientAuthenticationDigest::WithMaxHeaders<10> clientAuthentication{ args::get(passwordArgument), randomDataGenerator };
63+
static application::HttpClientAuthenticationDigest::WithMaxHeaders<10> clientAuthentication{ passwordArg, randomDataGenerator };
4464
static services::HttpClientAuthenticationConnector clientAuthenticationConnector{ connector, clientAuthentication };
45-
static application::FlexHttpClient httpClient(httpUrl, 80, clientAuthenticationConnector, firmware, webSocketInitiation, tracer.tracer);
65+
static application::FlexHttpClient httpClient(httpUrl, services::PortFromUrl(httpUrl).ValueOr(80), clientAuthenticationConnector, firmware, webSocketInitiation, tracer.tracer);
4666

4767
network.ExecuteUntil([&]()
4868
{

0 commit comments

Comments
 (0)