diff --git a/img/dockerizacija.excalidraw b/img/dockerizacija.excalidraw index b53fa5c..47757c6 100644 --- a/img/dockerizacija.excalidraw +++ b/img/dockerizacija.excalidraw @@ -8,8 +8,8 @@ "type": "rectangle", "x": 1308.709540932276, "y": -4000.958446223056, - "width": 2467.9999542236333, - "height": 917.9997444152832, + "width": 1880.0000762939458, + "height": 1382.9997444152834, "angle": 0, "strokeColor": "#1971c2", "backgroundColor": "transparent", @@ -24,11 +24,11 @@ "type": 3 }, "seed": 2088351519, - "version": 362, - "versionNonce": 489722065, + "version": 440, + "versionNonce": 952842321, "isDeleted": false, "boundElements": null, - "updated": 1704967702868, + "updated": 1704975528167, "link": null, "locked": false }, @@ -1595,10 +1595,10 @@ { "id": "ZlhzvaNeHw2kG3j_U_BVL", "type": "rectangle", - "x": 1901.709418861962, - "y": -3894.9583661144134, + "x": 1515.709663002586, + "y": -3882.958472925937, "width": 699.9998474121091, - "height": 650.9999084472656, + "height": 585.9999084472657, "angle": 0, "strokeColor": "#2f9e44", "backgroundColor": "#b2f2bb", @@ -1613,8 +1613,8 @@ "type": 3 }, "seed": 1301069471, - "version": 608, - "versionNonce": 97888657, + "version": 848, + "versionNonce": 220524177, "isDeleted": false, "boundElements": [ { @@ -1622,15 +1622,15 @@ "id": "vaFZ4NTM-ynAWN9xIuCgY" } ], - "updated": 1704967754619, + "updated": 1704975408926, "link": null, "locked": false }, { "id": "vaFZ4NTM-ynAWN9xIuCgY", "type": "text", - "x": 2169.629310219384, - "y": -3889.9583661144134, + "x": 1783.6295543600077, + "y": -3877.958472925937, "width": 164.16006469726562, "height": 45, "angle": 0, @@ -1645,11 +1645,11 @@ "frameId": null, "roundness": null, "seed": 1933434481, - "version": 323, - "versionNonce": 719336447, + "version": 459, + "versionNonce": 660134801, "isDeleted": false, "boundElements": null, - "updated": 1704967754619, + "updated": 1704975404256, "link": null, "locked": false, "text": "Container", @@ -1662,13 +1662,83 @@ "originalText": "Container", "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", "type": "text", - "x": 1974.7092204977048, - "y": -3757.9583966319915, + "x": 1583.7094646383289, + "y": -3717.9583966319915, "width": 548.4375, - "height": 345.59999999999997, + "height": 302.4, "angle": 0, "strokeColor": "#1e1e1e", "backgroundColor": "#b2f2bb", @@ -1681,21 +1751,57 @@ "frameId": null, "roundness": null, "seed": 368949983, - "version": 373, - "versionNonce": 269198047, + "version": 439, + "versionNonce": 316412863, "isDeleted": false, "boundElements": null, - "updated": 1704967668686, + "updated": 1704975396059, "link": null, "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, "fontFamily": 3, "textAlign": "left", "verticalAlign": "top", - "baseline": 337, + "baseline": 294, "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 }, { @@ -1737,12 +1843,12 @@ { "id": "OXdl7yMrTwt_w2o5BD9xR", "type": "rectangle", - "x": 2893.7093120504387, - "y": -3855.9584652965423, + "x": 2609.7095256734847, + "y": -3665.9584652965423, "width": 461.00006103515716, "height": 211.0000228881836, "angle": 0, - "strokeColor": "#f08c00", + "strokeColor": "#1e1e1e", "backgroundColor": "#ffc9c9", "fillStyle": "hachure", "strokeWidth": 2, @@ -1755,28 +1861,36 @@ "type": 3 }, "seed": 868345649, - "version": 40, - "versionNonce": 1538938207, + "version": 295, + "versionNonce": 335794449, "isDeleted": false, "boundElements": [ { "type": "text", "id": "IK6b1cadktRnvijOBY-A_" + }, + { + "id": "4wHvv2jklTmvU2a9iWU78", + "type": "arrow" + }, + { + "id": "0Pt16FjlsfV6CmvFOb6yM", + "type": "arrow" } ], - "updated": 1704967771734, + "updated": 1704975555926, "link": null, "locked": false }, { "id": "IK6b1cadktRnvijOBY-A_", "type": "text", - "x": 3052.0473247457517, - "y": -3772.9584538524505, - "width": 144.32403564453125, - "height": 45, + "x": 2639.8189311910633, + "y": -3582.0584538524504, + "width": 400.78125, + "height": 43.199999999999996, "angle": 0, - "strokeColor": "#f08c00", + "strokeColor": "#1e1e1e", "backgroundColor": "#ffc9c9", "fillStyle": "hachure", "strokeWidth": 2, @@ -1787,22 +1901,190 @@ "frameId": null, "roundness": null, "seed": 1222697521, - "version": 27, - "versionNonce": 1749250239, + "version": 300, + "versionNonce": 803766111, "isDeleted": false, "boundElements": null, - "updated": 1704967794238, + "updated": 1704975474606, "link": null, "locked": false, - "text": "/tmp/log", + "text": "/var/log/api-server", "fontSize": 36, - "fontFamily": 1, + "fontFamily": 3, "textAlign": "center", "verticalAlign": "middle", - "baseline": 31, + "baseline": 34, "containerId": "OXdl7yMrTwt_w2o5BD9xR", - "originalText": "/tmp/log", - "lineHeight": 1.25 + "originalText": "/var/log/api-server", + "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": { diff --git a/api-server-multistage/.dockerignore b/multistage-build/.dockerignore similarity index 100% rename from api-server-multistage/.dockerignore rename to multistage-build/.dockerignore diff --git a/api-server-multistage/Dockerfile b/multistage-build/Dockerfile similarity index 59% rename from api-server-multistage/Dockerfile rename to multistage-build/Dockerfile index 5bc8129..186c491 100644 --- a/api-server-multistage/Dockerfile +++ b/multistage-build/Dockerfile @@ -10,13 +10,19 @@ EXPOSE 3000 # create and set main app directory 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 . -# install dependencies +# install dependencies && cleanup 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 ENTRYPOINT ["/app/run.sh"] diff --git a/multistage-build/Dockerfile.multistage b/multistage-build/Dockerfile.multistage new file mode 100644 index 0000000..454ab66 --- /dev/null +++ b/multistage-build/Dockerfile.multistage @@ -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 [] diff --git a/api-server-multistage/Makefile b/multistage-build/Makefile similarity index 55% rename from api-server-multistage/Makefile rename to multistage-build/Makefile index 403e94d..d0fb094 100644 --- a/api-server-multistage/Makefile +++ b/multistage-build/Makefile @@ -1,13 +1,19 @@ -IMAGE_NAME=api-server -CONTAINER_NAME=api-server +IMAGE_NAME=api-server-ms +CONTAINER_NAME=api-server-ms build: clean @docker build \ --progress=plain \ - --no-cache \ --tag $(IMAGE_NAME) \ . +build-multistage: clean + @docker build \ + --progress=plain \ + --tag $(IMAGE_NAME) \ + --file Dockerfile.multistage \ + . + run: @docker run \ --name $(IMAGE_NAME) \ @@ -16,16 +22,6 @@ run: --detach \ $(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: - @docker stop $(CONTAINER_NAME) - @docker rm $(CONTAINER_NAME) diff --git a/api-server-multistage/app/Makefile b/multistage-build/app/Makefile similarity index 100% rename from api-server-multistage/app/Makefile rename to multistage-build/app/Makefile diff --git a/api-server-multistage/app/main.py b/multistage-build/app/main.py similarity index 100% rename from api-server-multistage/app/main.py rename to multistage-build/app/main.py diff --git a/api-server-multistage/app/requirements.txt b/multistage-build/app/requirements.txt similarity index 64% rename from api-server-multistage/app/requirements.txt rename to multistage-build/app/requirements.txt index 97dc7cd..343c205 100644 --- a/api-server-multistage/app/requirements.txt +++ b/multistage-build/app/requirements.txt @@ -1,2 +1,3 @@ fastapi uvicorn +psycopg2 diff --git a/api-server-multistage/app/run.sh b/multistage-build/app/run.sh similarity index 100% rename from api-server-multistage/app/run.sh rename to multistage-build/app/run.sh