Multistage build

This commit is contained in:
Eden Kirin
2024-01-11 13:20:06 +01:00
parent d96368feb6
commit 176d22bbe4
9 changed files with 396 additions and 60 deletions

View File

@ -8,8 +8,8 @@
"type": "rectangle", "type": "rectangle",
"x": 1308.709540932276, "x": 1308.709540932276,
"y": -4000.958446223056, "y": -4000.958446223056,
"width": 2467.9999542236333, "width": 1880.0000762939458,
"height": 917.9997444152832, "height": 1382.9997444152834,
"angle": 0, "angle": 0,
"strokeColor": "#1971c2", "strokeColor": "#1971c2",
"backgroundColor": "transparent", "backgroundColor": "transparent",
@ -24,11 +24,11 @@
"type": 3 "type": 3
}, },
"seed": 2088351519, "seed": 2088351519,
"version": 362, "version": 440,
"versionNonce": 489722065, "versionNonce": 952842321,
"isDeleted": false, "isDeleted": false,
"boundElements": null, "boundElements": null,
"updated": 1704967702868, "updated": 1704975528167,
"link": null, "link": null,
"locked": false "locked": false
}, },
@ -1595,10 +1595,10 @@
{ {
"id": "ZlhzvaNeHw2kG3j_U_BVL", "id": "ZlhzvaNeHw2kG3j_U_BVL",
"type": "rectangle", "type": "rectangle",
"x": 1901.709418861962, "x": 1515.709663002586,
"y": -3894.9583661144134, "y": -3882.958472925937,
"width": 699.9998474121091, "width": 699.9998474121091,
"height": 650.9999084472656, "height": 585.9999084472657,
"angle": 0, "angle": 0,
"strokeColor": "#2f9e44", "strokeColor": "#2f9e44",
"backgroundColor": "#b2f2bb", "backgroundColor": "#b2f2bb",
@ -1613,8 +1613,8 @@
"type": 3 "type": 3
}, },
"seed": 1301069471, "seed": 1301069471,
"version": 608, "version": 848,
"versionNonce": 97888657, "versionNonce": 220524177,
"isDeleted": false, "isDeleted": false,
"boundElements": [ "boundElements": [
{ {
@ -1622,15 +1622,15 @@
"id": "vaFZ4NTM-ynAWN9xIuCgY" "id": "vaFZ4NTM-ynAWN9xIuCgY"
} }
], ],
"updated": 1704967754619, "updated": 1704975408926,
"link": null, "link": null,
"locked": false "locked": false
}, },
{ {
"id": "vaFZ4NTM-ynAWN9xIuCgY", "id": "vaFZ4NTM-ynAWN9xIuCgY",
"type": "text", "type": "text",
"x": 2169.629310219384, "x": 1783.6295543600077,
"y": -3889.9583661144134, "y": -3877.958472925937,
"width": 164.16006469726562, "width": 164.16006469726562,
"height": 45, "height": 45,
"angle": 0, "angle": 0,
@ -1645,11 +1645,11 @@
"frameId": null, "frameId": null,
"roundness": null, "roundness": null,
"seed": 1933434481, "seed": 1933434481,
"version": 323, "version": 459,
"versionNonce": 719336447, "versionNonce": 660134801,
"isDeleted": false, "isDeleted": false,
"boundElements": null, "boundElements": null,
"updated": 1704967754619, "updated": 1704975404256,
"link": null, "link": null,
"locked": false, "locked": false,
"text": "Container", "text": "Container",
@ -1662,13 +1662,83 @@
"originalText": "Container", "originalText": "Container",
"lineHeight": 1.25 "lineHeight": 1.25
}, },
{
"id": "6-cRq4fP7v5zpj8uI6GIF",
"type": "rectangle",
"x": 1515.709663002586,
"y": -3248.9584576671477,
"width": 699.9998474121091,
"height": 585.9999084472657,
"angle": 0,
"strokeColor": "#2f9e44",
"backgroundColor": "#b2f2bb",
"fillStyle": "hachure",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": {
"type": 3
},
"seed": 1117121919,
"version": 929,
"versionNonce": 1025879903,
"isDeleted": false,
"boundElements": [
{
"type": "text",
"id": "QCqLOVxvrzqpkNO75Vjdu"
}
],
"updated": 1704975539217,
"link": null,
"locked": false
},
{
"id": "QCqLOVxvrzqpkNO75Vjdu",
"type": "text",
"x": 1783.6295543600077,
"y": -3243.9584576671477,
"width": 164.16006469726562,
"height": 45,
"angle": 0,
"strokeColor": "#2f9e44",
"backgroundColor": "#b2f2bb",
"fillStyle": "hachure",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 1277750769,
"version": 539,
"versionNonce": 345402239,
"isDeleted": false,
"boundElements": null,
"updated": 1704975539217,
"link": null,
"locked": false,
"text": "Container",
"fontSize": 36,
"fontFamily": 1,
"textAlign": "center",
"verticalAlign": "top",
"baseline": 31,
"containerId": "6-cRq4fP7v5zpj8uI6GIF",
"originalText": "Container",
"lineHeight": 1.25
},
{ {
"id": "heCWfyZvSZk60i37Hqy9u", "id": "heCWfyZvSZk60i37Hqy9u",
"type": "text", "type": "text",
"x": 1974.7092204977048, "x": 1583.7094646383289,
"y": -3757.9583966319915, "y": -3717.9583966319915,
"width": 548.4375, "width": 548.4375,
"height": 345.59999999999997, "height": 302.4,
"angle": 0, "angle": 0,
"strokeColor": "#1e1e1e", "strokeColor": "#1e1e1e",
"backgroundColor": "#b2f2bb", "backgroundColor": "#b2f2bb",
@ -1681,21 +1751,57 @@
"frameId": null, "frameId": null,
"roundness": null, "roundness": null,
"seed": 368949983, "seed": 368949983,
"version": 373, "version": 439,
"versionNonce": 269198047, "versionNonce": 316412863,
"isDeleted": false, "isDeleted": false,
"boundElements": null, "boundElements": null,
"updated": 1704967668686, "updated": 1704975396059,
"link": null, "link": null,
"locked": false, "locked": false,
"text": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── Makefile\n│   ├── requirements.txt\n│   └── run.sh\n", "text": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── requirements.txt\n│   └── run.sh\n",
"fontSize": 36, "fontSize": 36,
"fontFamily": 3, "fontFamily": 3,
"textAlign": "left", "textAlign": "left",
"verticalAlign": "top", "verticalAlign": "top",
"baseline": 337, "baseline": 294,
"containerId": null, "containerId": null,
"originalText": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── Makefile\n│   ├── requirements.txt\n│   └── run.sh\n", "originalText": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── requirements.txt\n│   └── run.sh\n",
"lineHeight": 1.2
},
{
"id": "MMjc1XqjKUJuVt-vaD9Wp",
"type": "text",
"x": 1583.7094646383289,
"y": -3083.9583813732024,
"width": 548.4375,
"height": 302.4,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "#b2f2bb",
"fillStyle": "hachure",
"strokeWidth": 2,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 967432639,
"version": 518,
"versionNonce": 316318623,
"isDeleted": false,
"boundElements": null,
"updated": 1704975539217,
"link": null,
"locked": false,
"text": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── requirements.txt\n│   └── run.sh\n",
"fontSize": 36,
"fontFamily": 3,
"textAlign": "left",
"verticalAlign": "top",
"baseline": 294,
"containerId": null,
"originalText": "├── app\n│   ├── log\n│   │   └── api-server.log\n│   ├── main.py\n│   ├── requirements.txt\n│   └── run.sh\n",
"lineHeight": 1.2 "lineHeight": 1.2
}, },
{ {
@ -1737,12 +1843,12 @@
{ {
"id": "OXdl7yMrTwt_w2o5BD9xR", "id": "OXdl7yMrTwt_w2o5BD9xR",
"type": "rectangle", "type": "rectangle",
"x": 2893.7093120504387, "x": 2609.7095256734847,
"y": -3855.9584652965423, "y": -3665.9584652965423,
"width": 461.00006103515716, "width": 461.00006103515716,
"height": 211.0000228881836, "height": 211.0000228881836,
"angle": 0, "angle": 0,
"strokeColor": "#f08c00", "strokeColor": "#1e1e1e",
"backgroundColor": "#ffc9c9", "backgroundColor": "#ffc9c9",
"fillStyle": "hachure", "fillStyle": "hachure",
"strokeWidth": 2, "strokeWidth": 2,
@ -1755,28 +1861,36 @@
"type": 3 "type": 3
}, },
"seed": 868345649, "seed": 868345649,
"version": 40, "version": 295,
"versionNonce": 1538938207, "versionNonce": 335794449,
"isDeleted": false, "isDeleted": false,
"boundElements": [ "boundElements": [
{ {
"type": "text", "type": "text",
"id": "IK6b1cadktRnvijOBY-A_" "id": "IK6b1cadktRnvijOBY-A_"
},
{
"id": "4wHvv2jklTmvU2a9iWU78",
"type": "arrow"
},
{
"id": "0Pt16FjlsfV6CmvFOb6yM",
"type": "arrow"
} }
], ],
"updated": 1704967771734, "updated": 1704975555926,
"link": null, "link": null,
"locked": false "locked": false
}, },
{ {
"id": "IK6b1cadktRnvijOBY-A_", "id": "IK6b1cadktRnvijOBY-A_",
"type": "text", "type": "text",
"x": 3052.0473247457517, "x": 2639.8189311910633,
"y": -3772.9584538524505, "y": -3582.0584538524504,
"width": 144.32403564453125, "width": 400.78125,
"height": 45, "height": 43.199999999999996,
"angle": 0, "angle": 0,
"strokeColor": "#f08c00", "strokeColor": "#1e1e1e",
"backgroundColor": "#ffc9c9", "backgroundColor": "#ffc9c9",
"fillStyle": "hachure", "fillStyle": "hachure",
"strokeWidth": 2, "strokeWidth": 2,
@ -1787,22 +1901,190 @@
"frameId": null, "frameId": null,
"roundness": null, "roundness": null,
"seed": 1222697521, "seed": 1222697521,
"version": 27, "version": 300,
"versionNonce": 1749250239, "versionNonce": 803766111,
"isDeleted": false, "isDeleted": false,
"boundElements": null, "boundElements": null,
"updated": 1704967794238, "updated": 1704975474606,
"link": null, "link": null,
"locked": false, "locked": false,
"text": "/tmp/log", "text": "/var/log/api-server",
"fontSize": 36, "fontSize": 36,
"fontFamily": 1, "fontFamily": 3,
"textAlign": "center", "textAlign": "center",
"verticalAlign": "middle", "verticalAlign": "middle",
"baseline": 31, "baseline": 34,
"containerId": "OXdl7yMrTwt_w2o5BD9xR", "containerId": "OXdl7yMrTwt_w2o5BD9xR",
"originalText": "/tmp/log", "originalText": "/var/log/api-server",
"lineHeight": 1.25 "lineHeight": 1.2
},
{
"id": "4wHvv2jklTmvU2a9iWU78",
"type": "arrow",
"x": 1827.7097087789539,
"y": -3650.9584271495696,
"width": 776.9999694824223,
"height": 64.76344359893028,
"angle": 0,
"strokeColor": "#e03131",
"backgroundColor": "#ffc9c9",
"fillStyle": "hachure",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": {
"type": 2
},
"seed": 2046307615,
"version": 408,
"versionNonce": 1522624415,
"isDeleted": false,
"boundElements": null,
"updated": 1704975546775,
"link": null,
"locked": false,
"points": [
[
0,
0
],
[
776.9999694824223,
64.76344359893028
]
],
"lastCommittedPoint": null,
"startBinding": null,
"endBinding": {
"elementId": "OXdl7yMrTwt_w2o5BD9xR",
"focus": 0.048972416724051906,
"gap": 4.9998474121084655
},
"startArrowhead": null,
"endArrowhead": "arrow"
},
{
"id": "Nx5dYl7pNVgPj3QYwf7Ys",
"type": "text",
"x": 2279.709373085595,
"y": -3735.958389002597,
"width": 780.46875,
"height": 43.199999999999996,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "#ffc9c9",
"fillStyle": "hachure",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 1477675871,
"version": 122,
"versionNonce": 296268831,
"isDeleted": false,
"boundElements": null,
"updated": 1704975478886,
"link": null,
"locked": false,
"text": "--volume /var/log/api-server:/app/log",
"fontSize": 36,
"fontFamily": 3,
"textAlign": "left",
"verticalAlign": "top",
"baseline": 34,
"containerId": null,
"originalText": "--volume /var/log/api-server:/app/log",
"lineHeight": 1.2
},
{
"id": "2TrOQMfKvhhqCOAIdX5QI",
"type": "text",
"x": 1320.7094341207514,
"y": -4108.95849581412,
"width": 147.65625,
"height": 43.199999999999996,
"angle": 0,
"strokeColor": "#1e1e1e",
"backgroundColor": "#ffc9c9",
"fillStyle": "hachure",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": null,
"seed": 812873823,
"version": 26,
"versionNonce": 1165128639,
"isDeleted": false,
"boundElements": null,
"updated": 1704975495017,
"link": null,
"locked": false,
"text": "Volumes",
"fontSize": 36,
"fontFamily": 3,
"textAlign": "left",
"verticalAlign": "top",
"baseline": 34,
"containerId": null,
"originalText": "Volumes",
"lineHeight": 1.2
},
{
"id": "0Pt16FjlsfV6CmvFOb6yM",
"type": "arrow",
"x": 1824.7093730855954,
"y": -3023.9583813732024,
"width": 781.0000610351558,
"height": 511.00006103515625,
"angle": 0,
"strokeColor": "#e03131",
"backgroundColor": "#ffc9c9",
"fillStyle": "hachure",
"strokeWidth": 4,
"strokeStyle": "solid",
"roughness": 1,
"opacity": 100,
"groupIds": [],
"frameId": null,
"roundness": {
"type": 2
},
"seed": 781261759,
"version": 39,
"versionNonce": 510232305,
"isDeleted": false,
"boundElements": null,
"updated": 1704975558752,
"link": null,
"locked": false,
"points": [
[
0,
0
],
[
781.0000610351558,
-511.00006103515625
]
],
"lastCommittedPoint": null,
"startBinding": null,
"endBinding": {
"elementId": "OXdl7yMrTwt_w2o5BD9xR",
"focus": 0.4991185163231458,
"gap": 4.0000915527334655
},
"startArrowhead": null,
"endArrowhead": "arrow"
} }
], ],
"appState": { "appState": {

View File

@ -10,13 +10,19 @@ EXPOSE 3000
# create and set main app directory # create and set main app directory
WORKDIR /app WORKDIR /app
# install sys libs and create virtual env
RUN \
apt update && \
apt install -y gcc libpq-dev python3-dev && \
python -m venv /venv
# copy app files to /app directory # copy app files to /app directory
COPY ./app . COPY ./app .
# install dependencies # install dependencies && cleanup
RUN \ RUN \
python -m venv /venv && \ pip install -r requirements.txt && \
pip install -r requirements.txt apt purge --auto-remove -y
# start shell script when container starts # start shell script when container starts
ENTRYPOINT ["/app/run.sh"] ENTRYPOINT ["/app/run.sh"]

View File

@ -0,0 +1,51 @@
FROM python:3.11-slim-bookworm AS install-dependencies
# create and set main app directory
WORKDIR /app
# set virtual env path
ENV \
PATH=/venv/bin:$PATH
# install sys libs and create virtual env
RUN \
apt update && \
apt install -y gcc libpq-dev python3-dev && \
python -m venv /venv
# copy app files to /app directory
COPY ./app/requirements.txt .
# install dependencies && cleanup
RUN \
pip install -r requirements.txt
FROM python:3.11-slim-bookworm
# set virtual env path
ENV \
PATH=/venv/bin:$PATH
# does nothing, for documentation only
EXPOSE 3000
# create and set main app directory
WORKDIR /app
COPY --from=install-dependencies /venv /venv
# copy app files to /app directory
COPY ./app .
RUN ls -alF /
RUN ls -alF /venv
RUN ls -alF /venv/bin
RUN ls -alF /app
# start shell script when container starts
ENTRYPOINT ["/app/run.sh"]
# no additional parameters to run.sh script
CMD []

View File

@ -1,13 +1,19 @@
IMAGE_NAME=api-server IMAGE_NAME=api-server-ms
CONTAINER_NAME=api-server CONTAINER_NAME=api-server-ms
build: clean build: clean
@docker build \ @docker build \
--progress=plain \ --progress=plain \
--no-cache \
--tag $(IMAGE_NAME) \ --tag $(IMAGE_NAME) \
. .
build-multistage: clean
@docker build \
--progress=plain \
--tag $(IMAGE_NAME) \
--file Dockerfile.multistage \
.
run: run:
@docker run \ @docker run \
--name $(IMAGE_NAME) \ --name $(IMAGE_NAME) \
@ -16,16 +22,6 @@ run:
--detach \ --detach \
$(CONTAINER_NAME) $(CONTAINER_NAME)
run-mount-log:
@docker run \
--name $(IMAGE_NAME) \
--publish 3000:3000 \
--volume /var/log/api-server:/app/log \
--env CONTAINER_NAME="Awesome API server" \
--detach \
$(CONTAINER_NAME)
clean: clean:
- @docker stop $(CONTAINER_NAME) - @docker stop $(CONTAINER_NAME)
- @docker rm $(CONTAINER_NAME) - @docker rm $(CONTAINER_NAME)

View File

@ -1,2 +1,3 @@
fastapi fastapi
uvicorn uvicorn
psycopg2