2023-11-06 01:56:49 -08:00
|
|
|
{{- if and (ne .host.distro.family "windows") (or (and (stat (joinPath .host.home ".config" "age" "chezmoi.txt")) (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "DOCKERHUB_TOKEN"))) (env "DOCKERHUB_TOKEN")) -}}
|
|
|
|
#!/usr/bin/env bash
|
|
|
|
# @file DockerHub Login
|
|
|
|
# @brief Logs into DockerHub for Docker Desktop
|
|
|
|
# @description
|
|
|
|
# This script logs into DockerHub so that Docker Desktop is pre-authenticated. This
|
|
|
|
# functionality requires that the `DOCKERHUB_USER` be passed in as an environment variable (or
|
|
|
|
# directly editted in the `~/.config/chezmoi/chezmoi.yaml` file) and that the `DOCKERHUB_TOKEN`
|
|
|
|
# be passed in as a secret (either via the encrypted secret method or passed in as an environment
|
|
|
|
# variable).
|
|
|
|
|
|
|
|
{{ includeTemplate "universal/profile" }}
|
|
|
|
{{ includeTemplate "universal/logg" }}
|
|
|
|
|
|
|
|
### Login to DockerHub
|
|
|
|
if command -v docker > /dev/null; then
|
|
|
|
DOCKERHUB_TOKEN="{{ if (stat (joinPath .chezmoi.sourceDir ".chezmoitemplates" "secrets" "DOCKERHUB_TOKEN")) }}{{- includeTemplate "secrets/DOCKERHUB_TOKEN" | decrypt | trim -}}{{ else }}{{- env "DOCKERHUB_TOKEN" -}}{{ end }}"
|
|
|
|
DOCKERHUB_USER="{{ .user.docker.username }}"
|
2023-12-05 23:11:40 -08:00
|
|
|
if [ -d "/Applications/Docker.app" ] || [ -d "$HOME/Applications/Docker.app" ]; then
|
|
|
|
logg info 'Ensuring Docker.app is open' && open --background -a Docker --args --accept-license --unattended
|
|
|
|
fi
|
2023-12-04 21:53:15 -08:00
|
|
|
logg info 'Headlessly authenticating with DockerHub registry' && echo "$DOCKERHUB_TOKEN" | docker login -u "$DOCKERHUB_USER" --password-stdin > /dev/null && logg success 'Successfully authenticated with DockerHub registry'
|
2023-11-06 01:56:49 -08:00
|
|
|
fi
|
|
|
|
|
|
|
|
{{- end }}
|