Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Cryptpad 5.1.0 #31

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ passwords.json
/mikeapp/
docker-compose.override*.yaml
dump.*

tasks.org
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ help:
@grep -h '^.PHONY: .* #' Makefile ${ROOT_DIR}/_scripts/Makefile.globals | sed 's/\.PHONY: \(.*\) # \(.*\)/make \1 \t- \2/' | expand -t20

include _scripts/Makefile.globals
include _scripts/Makefile.cd

.PHONY: check-deps
check-deps:
Expand Down Expand Up @@ -34,8 +35,7 @@ build:
find ./ | grep docker-compose.yaml$ | xargs dirname | xargs -iXX docker-compose --env-file=XX/${ENV_FILE} -f XX/docker-compose.yaml build

.PHONY: open # Open the repository website README
open:
xdg-open https://github.com/enigmacurry/d.rymcg.tech#readme
open: readme

.PHONY: status # Check status of all sub-projects
status:
Expand Down
73 changes: 47 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,12 +493,16 @@ As alluded to earlier, this project offers multiple ways to control
Docker:

1. Editing `.env` files by hand, and running `docker compose`
commands yourself.
commands yourself (this is a usable, but lower level, base
abstraction).
2. Running `make` targets that edit the `.env` files automatically
and runs `docker compose` for you (this is the author's preferred
method).
method, and the one that most of the documentation will actually
use).
3. Running the `d.rymcg.tech` CLI script, which runs the `make`
targets from any working directory.
targets from any working directory. (This method also includes
extra features such as creating your own new projects from
templates.)

All of these methods are compatible, and they will all get you to the
same place. The Makefiles offer a more streamlined approach with a
Expand All @@ -516,12 +520,27 @@ For all of the containers that you wish to install, do the following:
`docker-compose.yaml`
* Copy the example `.env-dist` to `.env`
* Edit all of the variables in `.env` according to the example and comments.
* Follow the README for instructons to start the containers.
* Create a
[`docker-compose.override.yaml`](https://docs.docker.com/compose/extends/#multiple-compose-files)
file by hand, copying from the template given in
`docker-compose.instance.yaml` (If the project does not have this
file, you can skip this step.) This [ytt](https://carvel.dev/ytt/)
template is mainly used for the service container labels, and has
logic for choosing which Traefik middlewares to apply. So you just
need to remove (comment out) the lines that don't apply in your
case. The override files are not committed into git, as they are
normally dynamically generated by the Makefiles and rendering from
the template on the fly. If you want to maintain these files by
hand, you can remove the exclusion of them from the
[.gitignore](.gitignore) and commit them with your own forked
repository.
* Follow the README for instructions to start the containers.
Generally, all you need to do is run: `docker compose up --build
-d` (This is the same thing that `make install` does)

When using `docker compose` by hand, it uses the `.env` file name by default.
You can change this behaviour by specifying the `--env-file` argument.
When using `docker compose` by hand, it uses the `.env` file name by
default. To use any other filename, specify the `--env-file` argument
(eg. when deploying multiple instances).

### Using the Makefiles

Expand All @@ -547,8 +566,9 @@ directory you are in.
* The suffix of the .env filename, `_default`, refers to the
[instance](#creating-multiple-instances-of-a-service) of the
service (each instance has a different name, with `_default` being
the default name, and this is typical when you are only deploying a
single instance.)
the default name. This default name is typical only when you are
deploying a single instance, otherwise you should use a unique name
for each instance.)
* Verify the configuration by looking at the contents of
`.env_${DOCKER_CONTEXT}_default`.
* Run `make install` to start the services. (this is the same thing as
Expand All @@ -564,11 +584,11 @@ directory you are in.

`make config` *does not literally* create a file named `.env`, but
rather one based upon the current docker context:
`.env_${DOCKER_CONTEXT}_default`. This allows for different configurations to
coexist in the same directory. All of the makefile commands operate
assuming this contextual environment file name, not `.env`. To switch
between configs, you switch your current docker context: `docker
context use {CONTEXT}`.
`.env_${DOCKER_CONTEXT}_default`. This allows for different
configurations to coexist in the same directory. All of the `make`
commands operate assuming this contextual environment file name, *not*
`.env`. To switch between configs, you switch your current docker
context: `docker context use {CONTEXT}`.

During `make config`, you will sometimes be asked to create HTTP Basic
Authentication passwords, and these passwords can be *optionally*
Expand Down Expand Up @@ -666,8 +686,9 @@ d.rymcg.tech cd
Press `Ctrl-D` to exit the sub-shell and jump back to wherever you
came from.

From any working directory, you can create a new, barebones, [external
project](#integrating-external-projects):
From any working directory, you can create a new, [external
project](#integrating-external-projects), based upon one of the
[included templates](_templates):

```
# This creates a new project directory in your current working directory:
Expand All @@ -676,7 +697,7 @@ project](#integrating-external-projects):
d.rymcg.tech create
```

Open the README for any project in your web browser:
Open any project's README file directly in your web browser:

```
## Open the main README
Expand All @@ -693,7 +714,7 @@ your `~/.bashrc` *after* the `eval` line that loads the main
`d.rymcg.tech` script):

```
## Create a short alias for the Traefik project:
## Example project alias: creates a shorter command used just for the Traefik project:
__d.rymcg.tech_project_alias traefik
```

Expand All @@ -709,14 +730,13 @@ project](#integrating-external-projects) (eg. named `mikeapp`), you can
create a command alias for it:

```
## External project alias:
## Example external project alias:
__d.rymcg.tech_project_alias mikeapp ~/git/mikeapp
```

With this alias installed, instead of running `make -C ~/git/mikeapp
install` you can now simply run `mikeapp install`.


If you want a different alias for the main script, you can add that too:

```
Expand Down Expand Up @@ -756,13 +776,14 @@ By default, all of the `make` targets will use the default
environment, but you can tell it use the instance environment instead,
by setting the `instance` (or `INSTANCE`) variable:

``` make instance=foo config # Configure a new or existing instance
named foo make instance=bar config # (Re)configures bar instance make
instance=foo install # This (re)installs only the foo instance make
instance=bar install # (Re)installs only bar instance make
instance=foo ps # This shows the containers status of the foo instance
make instance=foo stop # This stops the foo instance make instance=bar
destroy # This destroys only the bar instance
```
make instance=foo config # Configure a new or existing instance named foo
make instance=bar config # (Re)configures bar instance
make instance=foo install # This (re)installs only the foo instance
make instance=bar install # (Re)installs only bar instance
make instance=foo ps # This shows the containers status of the foo instance
make instance=foo stop # This stops the foo instance
make instance=bar destroy # This destroys only the bar instance

# Show the status of all instances of the current project subdirectory:
make status
Expand Down
5 changes: 5 additions & 0 deletions _scripts/Makefile.cd
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.PHONY: cd # Enter a Bash sub-shell and change working directory to the project root
cd:
@echo "Changing directory to ${CURDIR}"
@echo "Entering sub-shell (press Ctrl-D to pop back out)"
@bash --rcfile <(echo "source ~/.bashrc; unset PROMPT_COMMAND; PS1=\"[@] \$${PS1}\"") -i
1 change: 1 addition & 0 deletions _scripts/Makefile.project-subproject
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include ${ROOT_DIR}/_scripts/Makefile.build
include ${ROOT_DIR}/_scripts/Makefile.install
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
Expand Down
1 change: 1 addition & 0 deletions _scripts/Makefile.projects
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.open
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
1 change: 1 addition & 0 deletions _scripts/Makefile.projects-custom-build
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.open
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
Expand Down
1 change: 1 addition & 0 deletions _scripts/Makefile.projects-custom-build-custom-install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.open
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
Expand Down
1 change: 1 addition & 0 deletions _scripts/Makefile.projects-custom-install
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.open
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
1 change: 1 addition & 0 deletions _scripts/Makefile.projects-external
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.open
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
1 change: 1 addition & 0 deletions _scripts/Makefile.projects-no-open
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ include ${ROOT_DIR}/_scripts/Makefile.install
include ${ROOT_DIR}/_scripts/Makefile.lifecycle
include ${ROOT_DIR}/_scripts/Makefile.override
include ${ROOT_DIR}/_scripts/Makefile.clean
include ${ROOT_DIR}/_scripts/Makefile.cd
include ${ROOT_DIR}/_scripts/Makefile.reconfigure
include ${ROOT_DIR}/_scripts/Makefile.readme
include ${ROOT_DIR}/.env_$(shell ${BIN}/docker_context)
9 changes: 5 additions & 4 deletions _scripts/d.rymcg.tech
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,10 @@ __create() {
}

__change-directory() {
echo "Entering sub-shell. Press Ctrl-D to pop back to the parent shell."
if [[ $# -gt 0 ]]; then
/bin/bash --rcfile <(echo "cd ${ROOT_DIR}/$1")
__make $1 cd
else
/bin/bash --rcfile <(echo "cd ${ROOT_DIR}")
__make -- cd
fi
echo "Exited sub-shell."
}
Expand All @@ -112,7 +111,7 @@ __make() {
PROJECT_DIR=${ROOT_DIR}/${PROJECT_NAME}
fi
test -d "${PROJECT_DIR}" || fault "Project directory does not exist: ${PROJECT_DIR}"
make -C "${PROJECT_DIR}" "$@"
make --no-print-directory -C "${PROJECT_DIR}" "$@"
else
__list_projects
error "Missing project name argument. Choose one from the above."
Expand Down Expand Up @@ -358,6 +357,8 @@ main() {
__context "$@";;
script)
__run_script "$@";;
status)
__make -- status | sed "s|\./|${ROOT_DIR}/|g";;
*)
fault "Invalid command"
esac
Expand Down
33 changes: 23 additions & 10 deletions _scripts/docker_compose_override
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ fi
BIN=$(dirname ${BASH_SOURCE})
source ${BIN}/funcs.sh
ENV_FILE=$1; shift
YTT_DATA_ARGS=""

test -f docker-compose.instance.yaml || (echo "Missing docker-compose.instance.yaml. This project has not been setup with an override template yet." && exit 1)

DOCKER_CONTEXT=$(${BIN}/docker_context)
check_var DOCKER_CONTEXT
instance=${instance:-${INSTANCE}}
if [[ -n "${instance}" ]]; then
CONTEXT_INSTANCE="${DOCKER_CONTEXT}_${instance}"
Expand All @@ -22,28 +22,41 @@ else
fi
OVERRIDE="docker-compose.override_${CONTEXT_INSTANCE}.yaml"

YTT_DATA_ARGS="--data-value context=${DOCKER_CONTEXT}"

for var in "$@"; do
ytt_var="${var}"
value=""
#### The variable arguments have three forms:
#### name=VARIABLE_NAME # sets the name field to the value of VARIABLE_NAME in the .env file
#### name=:VARIABLE_NAME # sets the name field the literal string "VARIABLE_NAME"
#### name=@VARIABLE_NAME # sets the name field the literal string '${VARIABLE_NAME}'
if [[ "${var}" == *"=:"* ]]; then
# Get literal value from command line
parts=(${var//=:/ }); var=${parts[0]}; value=${parts[@]:1};
ytt_var="${var}"
else
elif [[ "${var}" == *"=@"* ]]; then
# Get literal value from command line and wrap it as a variable name ('VAR' becomes literal '${VAR}')
parts=(${var//=@/ }); var=${parts[0]}; value="\${${parts[1]}}";
ytt_var="${var}"
elif [[ "${var}" == *"="* ]]; then
# Get value from env file
if [[ "${var}" == *"="* ]]; then
# Make it an alias to a var in the env file:
parts=(${var//=/ }); var_alias=${parts[0]}; var=${parts[@]:1};
ytt_var="${var_alias}"
fi
parts=(${var//=/ }); var_alias=${parts[0]}; var=${parts[@]:1};
ytt_var="${var_alias}"
value="$(${BIN}/dotenv -f ${ENV_FILE} get $var)" || true
else
fault "Invalid arg var: ${var}"
fi
test -z "${value}" && echo "${var} is blank." && continue
test -z "${value}" && echo "${var} is blank."
ytt_var=$(echo "$ytt_var" | tr '[:upper:]' '[:lower:]')
YTT_DATA_ARGS="${YTT_DATA_ARGS} --data-value ${ytt_var}=\"${value}\""
YTT_DATA_ARGS="${YTT_DATA_ARGS} --data-value ${ytt_var}='${value}'"
done

echo '#' ytt ${YTT_DATA_ARGS} \< docker-compose.instance.yaml \> ${OVERRIDE}
ytt ${YTT_DATA_ARGS} < docker-compose.instance.yaml > ${OVERRIDE}
cat <<EOF > ${OVERRIDE}
## DO NOT EDIT - This Docker Compose override file is generated from the docker-compose.instance.yaml template.
## This file is automatically recreated whenever you run \`make config\` or \`make install\`.
EOF
ytt ${YTT_DATA_ARGS} < docker-compose.instance.yaml >> ${OVERRIDE}

echo "Created docker-compose override: ${OVERRIDE}"
3 changes: 3 additions & 0 deletions _scripts/open
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ EOF
}
if [[ -f passwords.json ]]; then
URL_PASSWORD=$(jq -r '(.["'${CONTEXT_INSTANCE}'"][0].username) + ":" + (.["'${CONTEXT_INSTANCE}'"][0].url_encoded)' <passwords.json)"@"
if [[ "${URL_PASSWORD}" == ":@" ]]; then
URL_PASSWORD=""
fi
else
URL_PASSWORD=""
fi
Expand Down
Loading