{"id":22284637,"url":"https://github.com/rillke/docker-env-file-update","last_synced_at":"2026-04-17T05:31:04.408Z","repository":{"id":72728109,"uuid":"115650779","full_name":"Rillke/Docker-env-file-update","owner":"Rillke","description":"Some handy scripts handling the update of .env files consumed by Docker during deployment when checking out a different version","archived":false,"fork":false,"pushed_at":"2018-02-21T11:41:38.000Z","size":19,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T20:19:26.829Z","etag":null,"topics":["bash-script","deployment","docker-compose","env","environment-variables","git-hooks","synchronization","update"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/Rillke.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-12-28T18:48:55.000Z","updated_at":"2024-03-04T06:46:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"a3433460-0159-4daa-a5d5-5aa1e8d719b3","html_url":"https://github.com/Rillke/Docker-env-file-update","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Rillke/Docker-env-file-update","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rillke%2FDocker-env-file-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rillke%2FDocker-env-file-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rillke%2FDocker-env-file-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rillke%2FDocker-env-file-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Rillke","download_url":"https://codeload.github.com/Rillke/Docker-env-file-update/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Rillke%2FDocker-env-file-update/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31916688,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T18:22:33.417Z","status":"online","status_checked_at":"2026-04-17T02:00:06.879Z","response_time":62,"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":["bash-script","deployment","docker-compose","env","environment-variables","git-hooks","synchronization","update"],"created_at":"2024-12-03T16:49:13.196Z","updated_at":"2026-04-17T05:31:04.390Z","avatar_url":"https://github.com/Rillke.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Update scripts for docker(-compose) env files [![Build Status](https://travis-ci.org/Rillke/Docker-env-file-update.svg?branch=master)](https://travis-ci.org/Rillke/Docker-env-file-update)\n\nSupplying environment variables through files is a convenient way to manage a larger number of configuration options applied through environment variables. Both, [docker](https://docs.docker.com/engine/reference/commandline/run/#set-environment-variables--e-env-env-file) and [docker-compose](https://docs.docker.com/compose/env-file/) support reading environment variables from a file.\n\nThe update scripts are intended to be used during manual deployments and expect stdin being available for prompting for your input.\n\n## Docker\n\n\u003e You can also load the environment variables from a file.\n\u003e This file should use the syntax `\u003cvariable\u003e=value` (which\n\u003e sets the variable to the given value) or `\u003cvariable\u003e`\n\u003e (which takes the value from the local environment),\n\u003e and `#` for comments.\n\nNote: Only the `\u003cvariable\u003e=value` syntax, blank lines and comments are supported by this collection of scripts (i.e. not `\u003cvariable\u003e`). Please feel free submitting merge requests to overcome this shortcoming.\n\n## Docker-compose\n\n\u003e Compose supports declaring default environment variables\n\u003e in an environment file named `.env` placed in the folder\n\u003e where the `docker-compose` command is executed (*current\n\u003e working directory*).\n\n\u003e These syntax rules apply to the .env file:\n\u003e\n\u003e - Compose expects each line in an `env` file to be in `VAR=VAL` format.\n\u003e - Lines beginning with `#` (i.e. comments) are ignored.\n\u003e - Blank lines are ignored.\n\u003e - There is no special handling of quotation marks (i.e. **they will be part of the VAL**, you have been warned ;) ).\n\n## Contents\n\n- Limitations:\n    - Install script will attempt attaching post-checkout hook to /dev/tty (Keyboard). This might break automated deployments. Do not use the script installer if your terminal is incompatible or if no keyboard device exists.\n    - Might not handle literal `\\n` in comments correctly. Please submit merge requests.\n- Requirements: Bash version 4 support or higher\n\n### update-env.sh\n\n- Updates an existing `.env` file with missing variables from a template file by prompting for their value (offering a default from the template).\n- Tracks who made the additions and when the additions were made.\n- Prints possibly unused/obsolete variables to stdout.\n\n### prettify-env.sh\n\n- Re-creates an existing `.env` file using a templates fills missing variables by prompting for their value (offering a default from the template)\n- Adds possibly unused/obsolete variables in a bottom section.\n- Because the whole file is rewritten each time, the template structure is restored. With `diff .env.example .env` changes to the default values from the template are easily spotted.\n\n## Git: Self-update when checking out another version\n\n### Using an installation script\n```sh\nwget -qO- https://raw.githubusercontent.com/Rillke/Docker-env-file-update/master/install.sh | bash\n```\n\n### Step by step\n\nGit provides so-called hooks. The `post-checkout` hook script is executed by Git after a new version is checked out (e.g. after a `git pull` or a `git checkout hash/tag/version`). This allows for keeping your `.env` file automatically up-to-date. Note that hooks are a local concept and do not become part of the repository, so install them in each clone of your repo you need them on.\n\nExample:\n\n0. Assuming that your template file's name is `.env.example` and your env file's name is `.env`.\n1. In your repository create a `.git/hooks/post-checkout` file with the follwing contents:\n\n```sh\n#!/bin/sh\n#\n# After you run a successful git checkout, the post-checkout hook runs;\n# you can use it to set up your working directory properly for your\n# project environment. This may mean moving in large binary files that\n# you don’t want source controlled, auto-generating documentation, or\n# something along those lines.\n\nif [ -f prettify-env.sh ]; then\n  bash prettify-env.sh .env.example .env\nelse\n  echo \"prettify-env.sh not found. Your .env file won't be updated.\"\nfi\n```\n\n2. Put a copy of `prettify-env.sh` into your repository (example is for the working directory but it should also work in the hidden `.git` directory if you adjust the paths in `.git/hooks/post-checkout` accordingly).\n3. Test, however note that `prettify-env.sh` will remove all customized comments from `.env`. If you do not wish this behaviour, use `update-env.sh` instead. For instance, try `git checkout master`\n\n### Uninstallation\n\nRemove the line invoking the script from `post-checkout`, or if this is the only command invoked, delete the `post-checkout` file entirely. By default, you can find the `post-checkout` hook file under `.git/hooks`. If the file does not exist, run the installation script again (abort it with `Ctrl`+`C` if necessary) and it will tell you where your `post-checkout` hook file is located.\n\n## Snippets\n\n### Convert Docker `.env` file to bash-compatible `.env` file format\n\n```sh\n# Load environment\neval $( cat .env | grep -v ^# | sed -r 's/([\"\\\\])/\\\\\\1/g' | sed -rn 's/([^\\=]+)\\=(.+)/\\1=\"\\2\"/p' )\n# Store into file\ncat .env | grep -v ^# | sed -r 's/([\"\\\\])/\\\\\\1/g' | sed -rn 's/([^\\=]+)\\=(.+)/\\1=\"\\2\"/p' \u003e .bash.env\n```\n\n1. Read `.env` file\n2. Strip comments\n3. Escape double quotes (`\"`) and backslashes (`\\`)\n4. Enclose values in double quotes\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frillke%2Fdocker-env-file-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frillke%2Fdocker-env-file-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frillke%2Fdocker-env-file-update/lists"}