do everything dockerfile added
This commit is contained in:
parent
df3284fe71
commit
c0c3ef4c76
64
Dockerfile
Normal file
64
Dockerfile
Normal file
@ -0,0 +1,64 @@
|
||||
# stage 1 generator - implementation code
|
||||
FROM python:3.10.0-bullseye AS stage1-builder
|
||||
|
||||
RUN mkdir /tmp/work && chown 1000 /tmp/work
|
||||
|
||||
COPY openapi.yaml /tmp/work
|
||||
COPY generateAll.sh /tmp/work
|
||||
COPY ENV /tmp/work
|
||||
COPY regular.cs.tmpl /tmp/work
|
||||
COPY generate.py /tmp/work
|
||||
COPY generateHelper.py /tmp/work
|
||||
|
||||
RUN \
|
||||
pip install Cheetah3 && \
|
||||
pip install PyYAML
|
||||
|
||||
USER 1000
|
||||
|
||||
RUN \
|
||||
cd /tmp/work && \
|
||||
./generateAll.sh -r1
|
||||
|
||||
|
||||
# stage 2 generator - openapi server stubs code and integration
|
||||
# with implementation and database code
|
||||
FROM openapitools/openapi-generator-cli:v5.3.0 AS stage2-builder
|
||||
|
||||
RUN mkdir /tmp/work && chown 1000 /tmp/work
|
||||
|
||||
USER 1000
|
||||
|
||||
COPY openapi.yaml /tmp/work
|
||||
COPY generateAll.sh /tmp/work
|
||||
COPY ENV /tmp/work
|
||||
COPY DbService.cs /tmp/work
|
||||
COPY --from=stage1-builder /tmp/work/regular.cs /tmp/work
|
||||
RUN cd /tmp/work && ./generateAll.sh -k2c
|
||||
|
||||
|
||||
# final container
|
||||
FROM wollud1969/dotnetcore5sdk:1.0.0
|
||||
|
||||
ENV Database__Password "xxx"
|
||||
|
||||
RUN \
|
||||
useradd -d /opt/service -m service && \
|
||||
mkdir /opt/service/output && chown service:service /opt/service/output
|
||||
|
||||
USER service
|
||||
WORKDIR /opt/service
|
||||
|
||||
COPY generateAll.sh .
|
||||
COPY ENV .
|
||||
COPY --from=stage2-builder /tmp/work/output/ ./output
|
||||
RUN ./generateAll.sh -kb
|
||||
|
||||
EXPOSE 8080
|
||||
|
||||
CMD [ "./generateAll.sh", "-kx" ]
|
||||
|
||||
|
||||
|
||||
|
||||
|
2
ENV
2
ENV
@ -3,7 +3,7 @@ export PACKAGE_NAME
|
||||
|
||||
Database__User=apiservicetestdb
|
||||
Database__Host=172.16.10.18
|
||||
Database__Password=xxx
|
||||
# Database__Password=xxx
|
||||
Database__Name=apiservicetestdb
|
||||
export Database__User Database__Host Database__Password Database__Name
|
||||
|
||||
|
@ -6,15 +6,19 @@ BUILD="0"
|
||||
EXECUTE="0"
|
||||
STAGE1="0"
|
||||
STAGE2="0"
|
||||
while getopts rxbh12 flag
|
||||
STAGE2_PRE_CONTAINER="0"
|
||||
KEEP="0"
|
||||
while getopts rxbh12ck flag
|
||||
do
|
||||
case "${flag}" in
|
||||
h)
|
||||
echo "1 ... generator stage 1 (implementation generator)";
|
||||
echo "2 ... generator stage 2 (openapi generator)";
|
||||
echo "r ... remove output directory";
|
||||
echo "k ... keep existing output directory";
|
||||
echo "b ... build after generating";
|
||||
echo "x ... execute after building";
|
||||
echo "c ... run stage in pre-started container";
|
||||
echo "h ... show help";
|
||||
|
||||
;;
|
||||
@ -33,6 +37,12 @@ do
|
||||
2)
|
||||
STAGE2="1"
|
||||
;;
|
||||
c)
|
||||
STAGE2_PRE_CONTAINER="1"
|
||||
;;
|
||||
k)
|
||||
KEEP="1"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@ -42,7 +52,7 @@ if [ "$REMOVE" = "1" ]; then
|
||||
fi
|
||||
|
||||
# safety measure
|
||||
if [ -d output ]; then
|
||||
if [ "$KEEP" = "0" -a -d output ]; then
|
||||
echo "output directory already exist"
|
||||
echo "remove manually and try again"
|
||||
exit 1
|
||||
@ -59,8 +69,15 @@ fi
|
||||
|
||||
if [ "$STAGE2" = "1" ]; then
|
||||
echo "generate server code and endpoint stubs from openapi.yaml"
|
||||
docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator-cli:v5.3.0 \
|
||||
generate -i /work/openapi.yaml -g aspnetcore -o /work/output \
|
||||
if [ "$STAGE2_PRE_CONTAINER" = "0" ]; then
|
||||
OPENAPI_GENERATOR_CMD="docker run -it --rm -v $PWD:/work -u $UID openapitools/openapi-generator-cli:v5.3.0"
|
||||
WORK_DIR="/work"
|
||||
else
|
||||
OPENAPI_GENERATOR_CMD="docker-entrypoint.sh"
|
||||
WORK_DIR="."
|
||||
fi
|
||||
$OPENAPI_GENERATOR_CMD \
|
||||
generate -i $WORK_DIR/openapi.yaml -g aspnetcore -o $WORK_DIR/output \
|
||||
--package-name $PACKAGE_NAME \
|
||||
--additional-properties="packageVersion=0.0.1,aspnetCoreVersion=5.0,operationIsAsync=false,operationResultTask=true,\
|
||||
generateBody=false,classModifier=abstract,operationModifier=abstract"
|
||||
@ -91,17 +108,18 @@ fi
|
||||
|
||||
if [ "$BUILD" = "1" ]; then
|
||||
echo "build service"
|
||||
cd output
|
||||
pushd output
|
||||
pushd src/$PACKAGE_NAME
|
||||
dotnet add package MySqlConnector --version 2.0.0
|
||||
popd
|
||||
sh build.sh
|
||||
popd
|
||||
fi
|
||||
|
||||
if [ "$EXECUTE" = "1" ]; then
|
||||
echo "execute service"
|
||||
dotnet run -p src/$PACKAGE_NAME/$PACKAGE_NAME.csproj
|
||||
dotnet run -p output/src/$PACKAGE_NAME/$PACKAGE_NAME.csproj
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user