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
151 lines (124 loc) · 4.19 KB
/
task.yaml
File metadata and controls
151 lines (124 loc) · 4.19 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
###########################################
# IMPORTANT
# Comments matter!
# The docs use the wrapping comments as
# markers for including said instructions
# as snippets in the docs.
###########################################
summary: Getting started with Django 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]
# [docs:create-project]
django-admin startproject django_hello_world
# [docs:create-project-end]
cd django_hello_world
python manage.py runserver &
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-django]
curl --fail localhost:8000
# [docs:curl-django-end]
kill $!
# [docs:create-rockcraft-yaml]
cd ..
rockcraft init --profile django-framework
# [docs:create-rockcraft-yaml-end]
sed -i "s/name: .*/name: django-hello-world/g" rockcraft.yaml
# [docs:pack]
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:django-hello-world_0.1_amd64.rock \
docker-daemon:django-hello-world:0.1
# [docs:skopeo-copy-end]
# [docs:docker-images]
sudo docker images django-hello-world:0.1
# [docs:docker-images-end]
# [docs:docker-run]
sudo docker run --rm -d -p 8000:8000 \
--name django-hello-world django-hello-world:0.1
# [docs:docker-run-end]
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-django-rock]
curl --fail localhost:8000
# [docs:curl-django-rock-end]
# [docs:get-logs]
sudo docker exec django-hello-world pebble logs django
# [docs:get-logs-end]
# [docs:stop-docker]
sudo docker stop django-hello-world
sudo docker rmi django-hello-world:0.1
# [docs:stop-docker-end]
# [docs:change-base]
sed -i \
"s/base: .*/base: bare\nbuild-base: ubuntu@22.04/g" \
rockcraft.yaml
# [docs:change-base-end]
sed -i "s/version: .*/version: 0.1-chiselled/g" rockcraft.yaml
# [docs:chisel-pack]
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:django-hello-world_0.1-chiselled_amd64.rock \
docker-daemon:django-hello-world:0.1-chiselled
sudo docker images django-hello-world:0.1-chiselled
sudo docker run --rm -d -p 8000:8000 \
--name django-hello-world django-hello-world:0.1-chiselled
# [docs:docker-run-chisel-end]
retry -n 5 --wait 2 curl --fail localhost:8000
# [docs:curl-django-bare-rock]
curl --fail localhost:8000
# [docs:curl-django-bare-rock-end]
# [docs:stop-docker-chisel]
sudo docker stop django-hello-world
sudo docker rmi django-hello-world:0.1-chiselled
# [docs:stop-docker-chisel-end]
# [docs:create-time-app]
cd django_hello_world
django-admin startapp time_app
# [docs:create-time-app-end]
cat ../time_app_views.py > time_app/views.py
cat ../time_app_urls.py > time_app/urls.py
cat ../urls.py > django_hello_world/urls.py
cd ..
sed -i "s/version: .*/version: 0.2/g" rockcraft.yaml
# [docs:docker-run-update]
rockcraft pack
sudo rockcraft.skopeo --insecure-policy copy \
oci-archive:django-hello-world_0.2_amd64.rock \
docker-daemon:django-hello-world:0.2
sudo docker images django-hello-world:0.2
sudo docker run --rm -d -p 8000:8000 \
--name django-hello-world django-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 django-hello-world
sudo docker rmi django-hello-world:0.2
# [docs:stop-docker-updated-end]
# [docs:cleanup]
# exit and delete the virtual environment
deactivate
rm -rf .venv django_hello_world __pycache__
# delete all the files created during the tutorial
rm django-hello-world_0.1_amd64.rock \
django-hello-world_0.1-chiselled_amd64.rock \
django-hello-world_0.2_amd64.rock \
rockcraft.yaml requirements.txt
# [docs:cleanup-end]