forked from canonical/rockcraft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.yaml
More file actions
137 lines (112 loc) · 3.98 KB
/
task.yaml
File metadata and controls
137 lines (112 loc) · 3.98 KB
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
###########################################
# IMPORTANT
# Comments matter!
# The docs use the wrapping comments as
# markers for including said instructions
# as snippets in the docs.
###########################################
summary: Getting started with FastAPI tutorial
environment:
execute: |
# [docs:create-venv]
sudo apt-get update && sudo apt-get install python3-venv -y
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# [docs:create-venv-end]
fastapi dev app.py --port 8000 &
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-fastapi]
curl --fail localhost:8000
# [docs:curl-fastapi-end]
kill $!
# [docs:create-rockcraft-yaml]
rockcraft init --profile fastapi-framework
# [docs:create-rockcraft-yaml-end]
sed -i "s/name: .*/name: fastapi-hello-world/g" rockcraft.yaml
# [docs:pack]
ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true rockcraft pack
# [docs:pack-end]
# [docs:ls-rock]
ls *.rock -l --block-size=MB
# [docs:ls-rock-end]
# [docs:skopeo-copy]
sudo rockcraft.skopeo --insecure-policy \
copy oci-archive:fastapi-hello-world_0.1_amd64.rock \
docker-daemon:fastapi-hello-world:0.1
# [docs:skopeo-copy-end]
# [docs:docker-images]
sudo docker images fastapi-hello-world:0.1
# [docs:docker-images-end]
# [docs:docker-run]
sudo docker run --rm -d -p 8000:8000 \
--name fastapi-hello-world fastapi-hello-world:0.1
# [docs:docker-run-end]
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-fastapi-rock]
curl --fail localhost:8000
# [docs:curl-fastapi-rock-end]
# [docs:get-logs]
sudo docker exec fastapi-hello-world pebble logs fastapi
# [docs:get-logs-end]
# [docs:stop-docker]
sudo docker stop fastapi-hello-world
sudo docker rmi fastapi-hello-world:0.1
# [docs:stop-docker-end]
# [docs:change-base]
sed -i \
"s/base: .*/base: bare\nbuild-base: ubuntu@24.04/g" \
rockcraft.yaml
# [docs:change-base-end]
sed -i "s/version: .*/version: 0.1-chiselled/g" rockcraft.yaml
# [docs:chisel-pack]
ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true rockcraft pack
# [docs:chisel-pack-end]
# [docs:ls-bare-rock]
ls *.rock -l --block-size=MB
# [docs:ls-bare-rock-end]
# [docs:docker-run-chisel]
sudo rockcraft.skopeo --insecure-policy \
copy oci-archive:fastapi-hello-world_0.1-chiselled_amd64.rock \
docker-daemon:fastapi-hello-world:0.1-chiselled
sudo docker images fastapi-hello-world:0.1-chiselled
sudo docker run --rm -d -p 8000:8000 \
--name fastapi-hello-world fastapi-hello-world:0.1-chiselled
# [docs:docker-run-chisel-end]
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-fastapi-bare-rock]
curl --fail localhost:8000
# [docs:curl-fastapi-bare-rock-end]
# [docs:stop-docker-chisel]
sudo docker stop fastapi-hello-world
sudo docker rmi fastapi-hello-world:0.1-chiselled
# [docs:stop-docker-chisel-end]
cat time_app.py > app.py
sed -i "s/version: .*/version: 0.2/g" rockcraft.yaml
# [docs:docker-run-update]
ROCKCRAFT_ENABLE_EXPERIMENTAL_EXTENSIONS=true rockcraft pack
sudo rockcraft.skopeo --insecure-policy \
copy oci-archive:fastapi-hello-world_0.2_amd64.rock \
docker-daemon:fastapi-hello-world:0.2
sudo docker images fastapi-hello-world:0.2
sudo docker run --rm -d -p 8000:8000 \
--name fastapi-hello-world fastapi-hello-world:0.2
# [docs:docker-run-update-end]
retry -n 5 --wait 2 curl --fail localhost:8000/time
# [docs:curl-time]
curl --fail localhost:8000/time
# [docs:curl-time-end]
# [docs:stop-docker-updated]
sudo docker stop fastapi-hello-world
sudo docker rmi fastapi-hello-world:0.2
# [docs:stop-docker-updated-end]
# [docs:cleanup]
# exit and delete the virtual environment
deactivate
rm -rf .venv __pycache__
# delete all the files created during the tutorial
rm fastapi-hello-world_0.1_amd64.rock \
fastapi-hello-world_0.1-chiselled_amd64.rock \
fastapi-hello-world_0.2_amd64.rock \
rockcraft.yaml app.py requirements.txt
# [docs:cleanup-end]