{"id":19073129,"url":"https://github.com/lowerdeez/devops-try","last_synced_at":"2025-10-04T17:04:11.441Z","repository":{"id":44608920,"uuid":"455675607","full_name":"LowerDeez/devops-try","owner":"LowerDeez","description":null,"archived":false,"fork":false,"pushed_at":"2022-02-09T15:17:57.000Z","size":276,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-12T05:53:11.592Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LowerDeez.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-02-04T19:43:56.000Z","updated_at":"2022-02-04T20:15:46.000Z","dependencies_parsed_at":"2022-09-13T14:21:52.790Z","dependency_job_id":null,"html_url":"https://github.com/LowerDeez/devops-try","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/LowerDeez/devops-try","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerDeez%2Fdevops-try","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerDeez%2Fdevops-try/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerDeez%2Fdevops-try/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerDeez%2Fdevops-try/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LowerDeez","download_url":"https://codeload.github.com/LowerDeez/devops-try/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LowerDeez%2Fdevops-try/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278343087,"owners_count":25971400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T01:45:32.164Z","updated_at":"2025-10-04T17:04:11.389Z","avatar_url":"https://github.com/LowerDeez.png","language":"Python","readme":"=========================\ndjango devops try project\n=========================\n\nSandbox project to try devops staff, CI\\CD etc.\n\nSteps of work\n=============\n\nCircleCI\n--------\n\n\n1. Prepare project with at least one application to run simple test with ``pytest`` for first circleci workflow.\n\n    1.1 Register at https://app.circleci.com/\n\n    1.2 Setup your project\n\n    1.3 Add ``.circleci`` folder with ``config.yml`` file\n\n2. ``config.yml`` - `First working version with comments \u003chttps://github.com/LowerDeez/devops-try/blob/7bd2928acd0e23438e7816e846690f00f444e381/.circleci/config.yml\u003e`_\n3. ``config.yml`` - `Add some code style checks (black, pylama, isort, migrations linter) \u003chttps://github.com/LowerDeez/devops-try/commit/8ed4e02a81c5302bcffb726b7baf0d8bd1d2d5eb\u003e`_\n4. `Add invoke tasks to update code style \u003chttps://github.com/LowerDeez/devops-try/commit/0c20d8161beb7731d12d2a32217fd5bb2b23d724\u003e`_.\n5. `Fix isort \u003chttps://github.com/LowerDeez/devops-try/commit/19b440d16fea8bb191c77c5ff89a6092fb2c0cbd\u003e`_.\n6. `Fix django-linter \u003chttps://github.com/LowerDeez/devops-try/commit/ecd8b3086ee06f150a29558f49c550d634b77ebf\u003e`_.\n7. Configure docker for \"production\"\n    7.1 Related articles\n        https://cookiecutter-django.readthedocs.io/en/latest/deployment-with-docker.html\n        https://testdriven.io/blog/dockerizing-django-with-postgres-gunicorn-and-nginx/\n        https://testdriven.io/blog/django-lets-encrypt/\n    7.2 Commands:\n        docker-compose -f production.yml run --user root --rm django bash -c \"cd server \u0026\u0026 python manage.py collectstatic --no-input --clear\" - collect static\n        docker-compose -f production.yml up -d --build\n        docker-compose -f production.yml exec django bash -c \"cd server \u0026\u0026 python manage.py migrate --noinput\"\n        docker-compose -f production.yml exec django bash -c \"cd server \u0026\u0026 python manage.py createsuperuser\"\n        docker-compose -f production.yml stop\n    7.3 `Commit with \"ready\" docker-compose file \u003chttps://github.com/LowerDeez/devops-try/commit/f884276f5ad09816de9a2e64020ef0a3c8ece517\u003e`_.\n\n8. How to setup AWS server (Both tutorials worth a check):\n    Articles to read\n        `Continuously Deploying Django to AWS EC2 with Docker and GitLab \u003chttps://testdriven.io/blog/deploying-django-to-ec2-with-docker-and-gitlab/#gitlab-ci-deploy-stage\u003e`_\n        `Deploying Django to AWS with Docker and Let's Encrypt (Main to setup AWS) \u003chttps://testdriven.io/blog/django-docker-https-aws/#running-the-containers\u003e`_\n\n    8.1. `Configuring AWS Credentials (Access key ID, Secret access key) \u003chttps://www.youtube.com/watch?v=qmtDRmplMG4\u003e`_\n    8.2. `Get Account id \u003chttps://console.aws.amazon.com/billing/home?#/account\u003e`_\n\n    8.3. Run ``aws configure``\n        AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE\n        AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY\n        Default region name [None]: us-west-1\n        Default output format [None]: json\n\n    8.4. Add postgres production variables to server/.env `with values from AWS \u003chttps://testdriven.io/blog/django-docker-https-aws/#aws-rds\u003e`_.\n         Postgres section should be removed from docker-compose:\n\n        POSTGRES_HOST=aws.host.us-east-1.rds.amazonaws.com\n        POSTGRES_PORT=5432\n        POSTGRES_DB=djangoec2\n        POSTGRES_USER=webapp\n        POSTGRES_PASSWORD=passwordd\n\n\n    8.5. build, login and push\n        docker-compose -f production.yml build\n        aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 123456789.dkr.ecr.us-east-1.amazonaws.com\n        docker-compose -f production.yml push\n\n9. Configure SSH connection for AWS instance, created along side with some of articles in 8.1 or 8.2\n    9.1 SSH into the instance using your Key Pair like so:\n        # example:\n        # ssh -i ~/.ssh/django.pem ec2-user@100.26.120.143\n    9.2 generate a new SSH key:\n        [ec2-user]$ ssh-keygen -t rsa\n    9.3 Save the key to /home/ec2-user/.ssh/id_rsa and don't set a password. This will generate a public and private key -- id_rsa and id_rsa.pub, respectively. To set up passwordless SSH login, copy the public key over to the `authorized_keys \u003chttps://security.stackexchange.com/questions/20706/what-is-the-difference-between-authorized-keys-and-known-hosts-file-for-ssh\u003e`_ file and set the proper permissions:\n        [ec2-user]$ cat ~/.ssh/id_rsa.pub\n        [ec2-user]$ vi ~/.ssh/authorized_keys\n        [ec2-user]$ chmod 600 ~/.ssh/authorized_keys\n        [ec2-user]$ chmod 600 ~/.ssh/id_rsa\n    9.4 Copy the contents of the private key:\n        [ec2-user]$ cat ~/.ssh/id_rsa\n    9.5 Exit the remote SSH session. Set the key as an environment variable on your local machine:\n        $ export PRIVATE_KEY='-----BEGIN RSA PRIVATE KEY-----\n        MIIEpAIBAAKCAQEA04up8hoqzS1+APIB0RhjXyObwHQnOzhAk5Bd7mhkSbPkyhP1\n        ...\n        iWlX9HNavcydATJc1f0DpzF0u4zY8PY24RVoW8vk+bJANPp1o2IAkeajCaF3w9nf\n        q/SyqAWVmvwYuIhDiHDaV2A==\n        -----END RSA PRIVATE KEY-----'\n    9.6. Add the key to the `ssh-agent \u003chttps://www.ssh.com/ssh/agent\u003e`_:\n        $ ssh-add - \u003c\u003c\u003c \"${PRIVATE_KEY}\"\n    9.7. To test, run:\n        $ ssh -o StrictHostKeyChecking=no ubuntu@\u003cYOUR_INSTANCE_IP\u003e whoami\n        ec2-user\n    9.8. If this will not work - use for private key value from cat ~/.ssh/django-devops-try.pem (Key Pair from aws)\n    9.9 Create project dir\n        ssh -o StrictHostKeyChecking=no ubuntu@18.206.2.247 mkdir /home/ubuntu/devops_try\n\n10. Add env variables to your project in CIRCLECI (Project Settings section)\n    AWS_ACCESS_KEY_ID\txxxx24EG\n    AWS_ACCOUNT_ID\txxxx7006\n    AWS_DEFAULT_REGION\txxxxst-1\n    AWS_ECR_ACCOUNT_URL\txxxx-ec2\n    AWS_SECRET_ACCESS_KEY\txxxxDI0S\n    EC2_PUBLIC_IP_ADDRESS\txxxx.247\n    PRIVATE_KEY\txxxx----\n    DEFAULT_SERVER\txxxx.247\n    DEFAULT_USER\txxxxntu\n    DJANGO_DB_URL\txxxxoec2\n    DJANGO_SECRET_KEY\txxxxoYHK\n    DJANGO_ALLOWED_HOSTS\txxxxp.ua\n11. `Update production.yml (remove db section) \u003chttps://github.com/LowerDeez/devops-try/commit/87604de7b4f3462cd731f4a6fbe24d42e4886358\u003e`_\n12. `Add yml config to build and push docker image \u003chttps://github.com/LowerDeez/devops-try/commit/0abac48f23d6dcd17c870456e35699f0acf37651\u003e`_\n13. `Add yml config to deploy and task to login to aws in CLI \u003chttps://github.com/LowerDeez/devops-try/commit/65b124050ce8e1b4e9b2ba8e9f473a338bc11f26\u003e`_\n    13.1 Move env file to ./envs/.production/\n    13.2 Added invoke tasks to deploy\n    13.3 Skip collect static in Dockerfile\n    13.4 Change ``DJANGO_DB_URL`` to DB_URL in Circleci to avoid overriding of default env name for DB with aws connection string\n14. Setup SSH connection from CircleCI to your instance (To perform automatic deployments, CircleCI is going to need to log in to our server and pull the latest code from our git repo. )\n    If you want to use separate user:\n        Related articles:\n            1. `How we use CircleCI with Git and DigitalOcean to streamline our deployments \u003chttps://medium.com/@tomnashflex/how-we-use-circleci-with-git-and-digitalocean-to-streamline-our-deployments-49a6a02b6dd6\u003e`_\n            2. `How To Automate Deployment Using CircleCI and GitHub on Ubuntu 18.04 \u003chttps://www.digitalocean.com/community/tutorials/how-to-automate-deployment-using-circleci-and-github-on-ubuntu-18-04\u003e`_\n        1. On local Machine\n            1.1 ssh-keygen -m PEM -t rsa -f ~/.ssh/id_rsa_circleci\n        2. On VPS\n            1.1 Add ``circleci`` user\n                sudo useradd -m -d /home/circleci -s /bin/bash circleci\n                sudo mkdir /home/circleci/.ssh\n        3. On local machine\n            cat ~/.ssh/id_rsa_circleci.pub - copy value\n        4. On VPS\n            sudo nano /home/circleci/.ssh/authorized_keys - paste from 3 step\n        5. On local machine\n            ssh circleci@my.droplet.ip -i ~/.ssh/id_rsa_circleci - test connection\n        6. Login to CircleCI\n        7. Go to your Project Settings and navigate to SSH Keys\n        8. cat ~/.ssh/id_rsa_circleci - copy value on local machine\n        9. Add SSH key in Additional SSH Keys section\n        10. Update ``DB_USER`` env variable with ``circleci`` at Project Setting Environment Variables section\n    If you want to use default user (i.e. ubuntu):\n        cat ~/.ssh/django-devops-try.pem - copy (key pair from AWS)\n        Add to CircleCI to SSH Keys\n        ``DEFAULT_USER`` = ubuntu\n15. `Update deploy task with images pull and up \u003chttps://github.com/LowerDeez/devops-try/commit/8ee8b68f675c7bec5a8aee529a53a4e1cb4d2451\u003e`_\n    15.1 Fixed nginx section in production.yml\n    P.S. Don't forget to push build after changes","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flowerdeez%2Fdevops-try","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flowerdeez%2Fdevops-try","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flowerdeez%2Fdevops-try/lists"}