aboutsummaryrefslogtreecommitdiff
path: root/jupyter_files/Untitled.ipynb
blob: feca323fbabc03cd0214c13655e2ffa3a8aa9dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "78a149e6-ef3b-4b6e-a633-0c1d2eb2a7b1",
   "metadata": {},
   "source": [
    "# Setting up Docker for FastAPI and Jenkins CI-CD on Gentoo\n",
    "\n",
    "## Prerequisites:\n",
    "- Docker\n",
    "- Jenkins\n",
    "- FastAPI\n",
    "\n",
    "## Preparations.\n",
    "\n",
    "\n",
    "Create directory for your stuff, call it tech_project, enter it."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4d35806b-a9f8-43b0-82fd-b9a669295562",
   "metadata": {},
   "outputs": [],
   "source": [
    "$ mkdir tech_project && cd tech_project"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdfd8575-625f-488b-aec3-73ce987086d2",
   "metadata": {},
   "source": [
    "Create virtual Python environment:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "42b86b21-ffa1-4d22-af97-a130b76e04d0",
   "metadata": {},
   "outputs": [],
   "source": [
    "$ python -m venv venv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba4a8e5c-5e31-4e67-9c8f-17c75b52f5e2",
   "metadata": {},
   "outputs": [],
   "source": [
    "You can activate it now with:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "edaeb7c2-f19a-4a6b-bb5f-4c5fd93dcf60",
   "metadata": {},
   "outputs": [],
   "source": [
    "$ source venv/bin/activate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ebfbc06-03a0-4380-a9aa-970aafdbde75",
   "metadata": {},
   "outputs": [],
   "source": [
    "(venv) - That's what should prepend your prompt now."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb6d9596-a6fd-4127-a626-e63851a3e38f",
   "metadata": {},
   "source": [
    "Create a requirements.txt file, check which versions of fastapi and pydantic you have and use those:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a199797a-73ea-4015-b58f-e87ead2ea3f0",
   "metadata": {},
   "outputs": [],
   "source": [
    "fastapi>=0.111\n",
    "pydantic>=2.7.3\n",
    "uvicorn>=0.30.1"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "25c4e82b-0685-400e-9f40-c171deefcc1f",
   "metadata": {},
   "source": [
    "Create a Dockerfile:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "237c5063-5370-4be7-8e29-e0e9802077e6",
   "metadata": {},
   "outputs": [],
   "source": [
    "FROM python:3.12\n",
    "WORKDIR app/ .\n",
    "COPY requirements.txt .\n",
    "RUN pip install --no-cache-dir -r requirements.txt\n",
    "CMD [\"python\", \"main.py\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2b41ff9-c9d3-4a84-bb22-0494990ef272",
   "metadata": {},
   "source": [
    "Start docker service (as root):"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "37b1ef3f-8ed1-4c40-9ce9-5e88843356f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "# rc-service docker start"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7df0e4c5-20f2-4367-be36-e43617dab0ed",
   "metadata": {},
   "source": [
    "Build docker image:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1220f1b3-1b2c-4bba-a51f-54bd1401b1ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "$ docker build -t fastapi_tech_blog ."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "36881148-8ff4-48e6-80d9-8c53a05bb90b",
   "metadata": {},
   "source": [
    "Watch if warn you and build:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c962a037-75ef-4b22-b46a-f24da4994be4",
   "metadata": {},
   "outputs": [],
   "source": [
    "WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\n",
    " ---> Removed intermediate container bb903c49b10d\n",
    " ---> 2a71d86268fd\n",
    "Step 5/7 : COPY . .\n",
    " ---> 9fdcdd3d46cb\n",
    "Step 6/7 : EXPOSE 8000\n",
    " ---> Running in e63e0e7b3ccc\n",
    " ---> Removed intermediate container e63e0e7b3ccc\n",
    " ---> 72d0d9f39af7\n",
    "Step 7/7 : CMD [\"python\", \"main.py\"]\n",
    " ---> Running in b49bc996f993\n",
    " ---> Removed intermediate container b49bc996f993\n",
    " ---> fb426f2a7e15\n",
    "Successfully built fb426f2a7e15\n",
    "Successfully tagged fastapi_tech_blog:latest"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}