Skip to content

Commit

Permalink
Merge branch 'master' of github.com:omidraha/mystack
Browse files Browse the repository at this point in the history
  • Loading branch information
omidraha committed Jan 9, 2019
2 parents 0f6a9b3 + 710a4ac commit aa209e4
Show file tree
Hide file tree
Showing 6 changed files with 268 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/deploy/kubernetes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ Install kubectl binary via curl
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
# To download a specific version
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.4.6/bin/linux/amd64/kubectl
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.13.1/bin/linux/amd64/kubectl
$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl
Expand Down Expand Up @@ -458,3 +458,10 @@ Labels are key/value pairs attached to objects and can be used in any number of
$ kubectl get services
$ kubectl describe services/kubernetes-bootcamp
Toturials
---------


https://www.digitalocean.com/community/tutorials/modernizing-applications-for-kubernetes

102 changes: 102 additions & 0 deletions src/django/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,105 @@ Translation
txt = 'Hello'
ugettext(txt)
'سلام'
Django User Group Object Permissions
------------------------------------


Add permission to user

.. code-block:: python
from django.contrib.auth.models import User
from django.contrib.auth.models import Permission
usr = User.objects.first()
perm = Permission.objects.get(name='Can edit org')
usr.user_permissions.add(perm)
Add user to group

.. code-block:: python
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
usr = User.objects.first()
grp = Group.objects.get(name='Operator')
grp.user_set.add(usr)
Add group to user

.. code-block:: python
from django.contrib.auth.models import User
from django.contrib.auth.models import Group
usr = User.objects.first()
grp = Group.objects.get(name='Operator')
usr.groups.add(grp)
Add permission to group

.. code-block:: python
from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission
perm = Permission.objects.get(name='can edit org')
grp = Group.objects.get(name='Operator')
grp.permissions.add(perm)
Create permission for an object

.. code-block:: python
from django.contrib.auth.models import Group
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from sample.models import SampleObj
ct = ContentType.objects.get_for_model(SampleObj)
perm = Permission.objects.create(codename='can edit org', name='Can Edit Org', content_type=ct)
Add a permission to a user/group during a django migration


.. code-block:: python
from django.contrib.auth.management import create_permissions
from django.db import migrations
def create_default_groups_and_permissions(apps, schema_editor):
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, verbosity=0)
app_config.models_module = None
# Now add your perms to group here
class Migration(migrations.Migration):
dependencies = [
('contenttypes', '0002_remove_content_type_name'),
]
operations = [
migrations.RunPython(create_default_groups_and_permissions)
]
Django rest DjangoModelPermissions

* ``GET`` requests require the user to have the ``view`` permission on the model.
* ``POST`` requests require the user to have the ``add`` permission on the model.
* ``PUT`` and ``PATCH`` requests require the user to have the ``change`` permission on the model.
* ``DELETE`` requests require the user to have the ``delete`` permission on the model.

https://www.django-rest-framework.org/api-guide/permissions/#djangomodelpermissions
21 changes: 21 additions & 0 deletions src/linux/cmds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1485,3 +1485,24 @@ Install fonts
.. code-block:: bash
$ font-manager
Install tzdata noninteractive
-----------------------------


.. code-block:: bash
$ apt-get install -y tzdata
$ ln -fs /usr/share/zoneinfo/Asia/Tehran /etc/localtime
$ dpkg-reconfigure --frontend noninteractive tzdata
If you are fine with UTC:


.. code-block:: bash
$ DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata
18 changes: 18 additions & 0 deletions src/python/celery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,21 @@ http://stackoverflow.com/a/36977126

http://docs.celeryproject.org/en/latest/userguide/canvas.html#signatures


Chain tasks on celery
---------------------



.. code-block:: bash
t1 = my_task_01.subtask((arg1,), immutable=True)
t2 = my_task_02.subtask((arg1, arg2), immutable=True)
t3 = my_task_01.subtask((arg1,), immutable=True)
task_list = [t1, t2, t3]
tasks = chain(task_list)
tasks.apply_async()
The next task will run, if previous task run successfully.
The `immutable` option is set to `True`, so the result of each task won't send to the next task.
30 changes: 30 additions & 0 deletions src/vcs/git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -751,3 +751,33 @@ Related error: Git: cannot checkout branch - error: pathspec did not match any
rc
dev
Fix git remote fatal: index-pack failed
-----------------------------

Traceback:

.. code-block:: bash
or@omid:~/ws$ git clone git@bitbucket.org:example/example.git
Cloning into 'example'...
remote: Counting objects: 39831, done.
remote: Compressing objects: 100% (16929/16929), done.
Connection to bitbucket.org closed by remote host. 163.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOFs: 99% (39758/39831), 19.57 MiB | 166.00 KiB/s
fatal: index-pack failed
Solution:

.. code-block:: bash
$ git config --global core.compression 0
$ git clone --depth 1 git@bitbucket.org:example/example.git
# retrieve the rest of the clone
$ git fetch --unshallow
# or, alternately:
$ git fetch --depth=2147483647
$ git pull --all
89 changes: 89 additions & 0 deletions src/virtualization/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -476,3 +476,92 @@ Set image name when building a custom image
.. code-block:: bash
$ docker build -t image_name .
Set environment variables during the build in docker
----------------------------------------------------

.. code-block:: bash
FROM ubuntu:18.04
RUN apt-get update
ARG DEBIAN_FRONTEND=noninteractive
The `ARG` is for setting environment variables which are used during the docker build process,
and they are not present in the final image


Remove unused, <none>, untag docker images file
-----------------------------------------------


.. code-block:: bash
$ docker image prune -f
https://docs.docker.com/engine/reference/commandline/image_prune/#usage


Disable auto-restart on a container
-----------------------------------


.. code-block:: bash
$ docker update --restart=no container-id
Minimal base docker OS images
-----------------------------



* https://registry.hub.docker.com/_/ubuntu/

* https://registry.hub.docker.com/u/library/debian/

* https://registry.hub.docker.com/_/busybox/

* https://registry.hub.docker.com/_/centos/

* https://registry.hub.docker.com/_/fedora/

* https://registry.hub.docker.com/_/alpine/

* https://registry.hub.docker.com/_/cirros/

* https://hub.docker.com/_/python/

* https://github.com/GoogleContainerTools/distroless

https://www.brianchristner.io/docker-image-base-os-size-comparison/

.. code-block:: bash
$ docker pull python:3.6-alpine
$ docker images | grep -i python
# python 3.6-alpine cb04a359db13 3 days ago 74.3MB
https://github.com/docker-library/python


.. code-block:: bash
$ docker pull gcr.io/distroless/python3
$ docker images | grep -i distroless
# gcr.io/distroless/python3 latest 523f07cec1e2 49 years ago 50.9MB
Note that there is no ```docker exec(run) -it ...``` in `distroless` image.

https://github.com/GoogleContainerTools/distroless


Links:

https://medium.com/c0d1um/building-django-docker-image-with-alpine-32de65d2706

https://www.caktusgroup.com/blog/2017/03/14/production-ready-dockerfile-your-python-django-app/

0 comments on commit aa209e4

Please sign in to comment.