feat(ci): refactor build-and-deploy workflow with consistent formatting and dynamic dotenv handling
- Standardized YAML indentation and quoting in build-and-deploy workflow - Enhanced dotenv scripts to support custom .env file paths and dynamic entry naming based on project and branch - Added new `show-dotenv` utility to display dotenv configuration details - Updated documentation to reflect dynamic entry resolution and new command options - Fixed minor typos and improved consistency in patterns.md and library.md
This commit is contained in:
9 files changed
+128
-96
No files matched your search
@@ -1,67 +1,67 @@
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "main"
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
build:
|
||||
name: Build Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Create Kubeconfig for Buildx
|
||||
run: |
|
||||
mkdir -p $HOME/.kube
|
||||
echo "${{ secrets.KUBECONFIG_BUILDX }}" > $HOME/.kube/config
|
||||
- name: Create Kubeconfig for Buildx
|
||||
run: |
|
||||
mkdir -p $HOME/.kube
|
||||
echo "${{ secrets.KUBECONFIG_BUILDX }}" > $HOME/.kube/config
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: kubernetes
|
||||
driver-opts: |
|
||||
namespace=codeberg
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
with:
|
||||
driver: kubernetes
|
||||
driver-opts: |
|
||||
namespace=codeberg
|
||||
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: janikvonrotz
|
||||
password: ${{ secrets.DOCKER_PAT }}
|
||||
- name: Login to Docker Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: janikvonrotz
|
||||
password: ${{ secrets.DOCKER_PAT }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: image/Dockerfile
|
||||
platforms: linux/amd64
|
||||
tags: "janikvonrotz/taskfile.build:latest"
|
||||
push: true
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: image/Dockerfile
|
||||
platforms: linux/amd64
|
||||
tags: 'janikvonrotz/taskfile.build:latest'
|
||||
push: true
|
||||
|
||||
deploy:
|
||||
name: Deploy to Kubernetes
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
needs: build
|
||||
deploy:
|
||||
name: Deploy to Kubernetes
|
||||
runs-on: ubuntu-latest
|
||||
container: catthehacker/ubuntu:act-latest
|
||||
needs: build
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install kubectl
|
||||
run: |
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
chmod +x kubectl
|
||||
sudo mv kubectl /usr/local/bin/
|
||||
- name: Install kubectl
|
||||
run: |
|
||||
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
|
||||
chmod +x kubectl
|
||||
sudo mv kubectl /usr/local/bin/
|
||||
|
||||
- name: Create Kubeconfig for Deployment
|
||||
run: |
|
||||
mkdir -p $HOME/.kube
|
||||
echo "${{ secrets.KUBECONFIG_DEPLOY }}" > $HOME/.kube/config
|
||||
- name: Create Kubeconfig for Deployment
|
||||
run: |
|
||||
mkdir -p $HOME/.kube
|
||||
echo "${{ secrets.KUBECONFIG_DEPLOY }}" > $HOME/.kube/config
|
||||
|
||||
- name: Verify kubectl version
|
||||
run: kubectl version --client
|
||||
- name: Verify kubectl version
|
||||
run: kubectl version --client
|
||||
|
||||
- name: Deploy to Kubernetes
|
||||
run: kubectl delete pods -l app=taskfile-build -n taskfile-build
|
||||
- name: Deploy to Kubernetes
|
||||
run: kubectl delete pods -l app=taskfile-build -n taskfile-build
|
||||
@@ -1,11 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
load-dotenv-from-keepass() {
|
||||
echo "Restore .env file from keepassxc: $KEEPASS_ENTRY"
|
||||
KEEPASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
DOTENV=".env"
|
||||
if [[ -n "$1" ]]; then
|
||||
DOTENV="$1"
|
||||
fi
|
||||
|
||||
echo "Restore $DOTENV file from keepassxc: $KEEPASS_ENTRY"
|
||||
keepassxc-cli attachment-export \
|
||||
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
||||
"$KEEPASS_DATABASE_FILE" \
|
||||
"$KEEPASS_ENTRY" \
|
||||
".env" \
|
||||
".env"
|
||||
"$DOTENV" \
|
||||
"$DOTENV"
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
load-dotenv-from-pass() {
|
||||
PASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
DOTENV=".env"
|
||||
if [[ -n "$1" ]]; then
|
||||
DOTENV="$1"
|
||||
fi
|
||||
|
||||
if pass find "$PASS_ENTRY" >/dev/null; then
|
||||
echo "Restore .env file from pass: $PASS_ENTRY"
|
||||
pass show "$PASS_ENTRY" > .env
|
||||
echo "Restore $DOTENV file from pass: $PASS_ENTRY"
|
||||
pass show "$PASS_ENTRY" > $DOTENV
|
||||
else
|
||||
echo "Pass entry not found."
|
||||
fi
|
||||
|
||||
+15
-14
@@ -1,8 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
save-dotenv-to-keepass() {
|
||||
if [[ ! -f .env ]]; then
|
||||
echo "No .env file found."
|
||||
KEEPASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
DOTENV=".env"
|
||||
if [[ -n "$1" ]]; then
|
||||
DOTENV="$1"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$DOTENV" ]]; then
|
||||
echo "No $DOTENV file found."
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -10,7 +16,6 @@ save-dotenv-to-keepass() {
|
||||
read -s -p "Enter password to unlock $KEEPASS_DATABASE_FILE: " keepass_database_pass
|
||||
echo # Add a newline after password input
|
||||
|
||||
# Check if the entry already exists
|
||||
if echo "$keepass_database_pass" | keepassxc-cli show \
|
||||
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
||||
--quiet \
|
||||
@@ -20,35 +25,31 @@ save-dotenv-to-keepass() {
|
||||
echo "Entry '$KEEPASS_ENTRY' already exists."
|
||||
|
||||
# Try to remove existing .env attachment if it exists
|
||||
echo "Removing existing .env attachment (if any)..."
|
||||
echo "Removing existing $DOTENV attachment (if any)..."
|
||||
echo "$keepass_database_pass" | keepassxc-cli attachment-rm \
|
||||
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
||||
--quiet \
|
||||
"$KEEPASS_DATABASE_FILE" \
|
||||
"$KEEPASS_ENTRY" \
|
||||
".env" 2>/dev/null
|
||||
"$DOTENV" 2>/dev/null
|
||||
|
||||
else
|
||||
echo "Creating new entry: $KEEPASS_ENTRY"
|
||||
|
||||
# Create the entry with a placeholder password (required)
|
||||
echo "$keepass_database_pass" | keepassxc-cli add \
|
||||
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
||||
--quiet \
|
||||
--password-prompt \
|
||||
"$KEEPASS_DATABASE_FILE" \
|
||||
"$KEEPASS_ENTRY" <<< ""
|
||||
"$KEEPASS_ENTRY"
|
||||
fi
|
||||
|
||||
# Attach the .env file
|
||||
echo "Attaching .env file..."
|
||||
echo "Attaching $DOTENV file..."
|
||||
echo "$keepass_database_pass" | keepassxc-cli attachment-import \
|
||||
--key-file "$KEEPASS_DATABASE_KEY_FILE" \
|
||||
--quiet \
|
||||
"$KEEPASS_DATABASE_FILE" \
|
||||
"$KEEPASS_ENTRY" \
|
||||
".env" \
|
||||
".env"
|
||||
"$DOTENV" \
|
||||
"$DOTENV"
|
||||
|
||||
echo "Successfully saved .env as an attachment to '$KEEPASS_ENTRY'."
|
||||
echo "Successfully saved $DOTENV as an attachment to '$KEEPASS_ENTRY'."
|
||||
}
|
||||
+10
-4
@@ -1,10 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
save-dotenv-to-pass() {
|
||||
if [[ -f .env ]]; then
|
||||
echo "Store .env file in pass: $PASS_ENTRY"
|
||||
cat .env | pass insert -m -f "$PASS_ENTRY"
|
||||
PASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
DOTENV=".env"
|
||||
if [[ -n "$1" ]]; then
|
||||
DOTENV="$1"
|
||||
fi
|
||||
|
||||
if [[ -f "$DOTENV" ]]; then
|
||||
echo "Store $DOTENV file in pass: $PASS_ENTRY"
|
||||
cat "$DOTENV" | pass insert -m -f "$PASS_ENTRY"
|
||||
else
|
||||
echo "No .env file found."
|
||||
echo "No $DOTENV file found."
|
||||
fi
|
||||
}
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
show-dotenv() {
|
||||
PASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
KEEPASS_ENTRY=$(echo "env/${PWD##*/}#$(git symbolic-ref --short -q HEAD)" | tr '[:upper:]' '[:lower:]')
|
||||
echo "KeePass Database File: $KEEPASS_DATABASE_FILE"
|
||||
echo "KeePass Database Key File: $KEEPASS_DATABASE_KEY_FILE"
|
||||
echo "KeePass Entry: $KEEPASS_ENTRY"
|
||||
echo "Pass Entry: $PASS_ENTRY"
|
||||
}
|
||||
+18
-16
@@ -34,10 +34,10 @@ fi
|
||||
|
||||
These commands create folder in the directory of the task file and the home directory. Here is an overview of these folders:
|
||||
|
||||
* `$PWD/tmp`: Temporary directory for the task commands.
|
||||
* `$PWD/.prompt`: LLM prompts stored as markdown files.
|
||||
* `$HOME/.config/taskfile.build`: Default path for storing dotenv files.
|
||||
* `$HOME/.docker/$CONTAINER_REGISTRY`: Default path for storing container registry credentials.
|
||||
- `$PWD/tmp`: Temporary directory for the task commands.
|
||||
- `$PWD/.prompt`: LLM prompts stored as markdown files.
|
||||
- `$HOME/.config/taskfile.build`: Default path for storing dotenv files.
|
||||
- `$HOME/.docker/$CONTAINER_REGISTRY`: Default path for storing container registry credentials.
|
||||
|
||||
## Task
|
||||
|
||||
@@ -54,7 +54,6 @@ TASK_DOTENV_DIR="$HOME/Odoo-Build/config" # Default: "$HOME/.config/taskfile.bui
|
||||
printf "$column" 'clone-taskfile' '' 'Clone the taskfile.build repo.'
|
||||
```
|
||||
|
||||
|
||||
### init-config-dir
|
||||
|
||||
```bash
|
||||
@@ -79,6 +78,12 @@ printf "$column" 'open-with-os' '' 'Open file or url with default application.'
|
||||
printf "$column" 'open-url-with-delay' '[url][delay]' 'Open url after n seconds.'
|
||||
```
|
||||
|
||||
### show-dotenv
|
||||
|
||||
```bash
|
||||
printf "$column" 'show-dotenv' '' 'Show info about the dotenv setup.'
|
||||
```
|
||||
|
||||
## Files
|
||||
|
||||
Managing files and directories.
|
||||
@@ -279,36 +284,33 @@ printf "$column" 'update-submodule' '' 'Update git submodules.'
|
||||
|
||||
Load and store secrets from pass.
|
||||
|
||||
Set path to pass entry.
|
||||
|
||||
```bash
|
||||
PASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]')
|
||||
```
|
||||
The name of the entry will resolve dynamically depending on the current directory / project. Use `show-dotenv` to show info about the dotenv setup.
|
||||
|
||||
### save-dotenv-to-pass
|
||||
|
||||
```bash
|
||||
printf "$column" 'save-dotenv-to-pass' '' 'Store content of .env in pass entry.'
|
||||
printf "$column" 'save-dotenv-to-pass' '[file]' 'Store content of .env in pass entry.'
|
||||
```
|
||||
|
||||
### load-dotenv-from-pass
|
||||
|
||||
```bash
|
||||
printf "$column" 'load-dotenv-from-pass' '' 'Restore content to .env from pass entry.'
|
||||
printf "$column" 'load-dotenv-from-pass' '[file]' 'Restore content to .env from pass entry.'
|
||||
```
|
||||
|
||||
## KeePass
|
||||
|
||||
Load and store secrets from KeePassXC.
|
||||
|
||||
Set path to KeePassXC database and entry.
|
||||
Set path to KeePassXC database and entry:
|
||||
|
||||
```bash
|
||||
KEEPASS_DATABASE_FILE="/path/to/database.kdbx"
|
||||
KEEPASS_DATABASE_KEY_FILE="/path/to/keepass.key"
|
||||
KEEPASS_ENTRY=$(echo "env/${PWD##*/}" | tr '[:upper:]' '[:lower:]')
|
||||
```
|
||||
|
||||
The name of the entry will resolve dynamically depending on the current directory / project. Use `show-dotenv` to show info about the dotenv setup.
|
||||
|
||||
### save-pass-to-keepass
|
||||
|
||||
```bash
|
||||
@@ -324,13 +326,13 @@ printf "$column" 'get-pass-from-keepass' '[entry]' 'Get password from KeePass en
|
||||
### save-dotenv-to-keepass
|
||||
|
||||
```bash
|
||||
printf "$column" 'save-dotenv-to-keepass' '' 'Store content of .env in KeePass entry.'
|
||||
printf "$column" 'save-dotenv-to-keepass' '[file]' 'Store content of .env in KeePass entry.'
|
||||
```
|
||||
|
||||
### load-dotenv-from-keepass
|
||||
|
||||
```bash
|
||||
printf "$column" 'load-dotenv-from-keepass' '' 'Restore content to .env from KeePass entry.'
|
||||
printf "$column" 'load-dotenv-from-keepass' '[file]' 'Restore content to .env from KeePass entry.'
|
||||
```
|
||||
|
||||
## Kubernetes
|
||||
|
||||
+1
-1
@@ -285,7 +285,7 @@ process-data() {
|
||||
|
||||
## Check commands
|
||||
|
||||
Add the following statements to check if the required commands is available:
|
||||
Add the following statements to check if the required commands is available:
|
||||
|
||||
```python
|
||||
if ! (command -v grep &> /dev/null && grep --version | grep -q GNU) && [[ "$OS_RELEASE" =~ ^(Darwin)$ ]]; then
|
||||
|
||||
+3
-2
@@ -20,6 +20,7 @@ help-table() {
|
||||
printf "$column" 'template-dotenv' '' 'Generate .env from .env.template.'
|
||||
printf "$column" 'open-with-os' '' 'Open file or url with default application.'
|
||||
printf "$column" 'open-url-with-delay' '[url][delay]' 'Open url after n seconds.'
|
||||
printf "$column" 'show-dotenv' '' 'Show info about the dotenv setup.'
|
||||
# Files
|
||||
printf "$column" 'ensure-directory' '[path]' 'Ensure directory path exists.'
|
||||
printf "$column" 'create-symlink' '[target][source]' 'Remove existing file/directory and create symlink.'
|
||||
@@ -60,8 +61,8 @@ help-table() {
|
||||
# KeePass
|
||||
printf "$column" 'save-pass-to-keepass' '[pass][entry]' 'Store password to KeePass entry.'
|
||||
printf "$column" 'get-pass-from-keepass' '[entry]' 'Get password from KeePass entry.'
|
||||
printf "$column" 'save-dotenv-to-keepass' '' 'Store content of .env in KeePass entry.'
|
||||
printf "$column" 'load-dotenv-from-keepass' '' 'Restore content to .env from KeePass entry.'
|
||||
printf "$column" 'save-dotenv-to-keepass' '[file]' 'Store content of .env in KeePass entry.'
|
||||
printf "$column" 'load-dotenv-from-keepass' '[file]' 'Restore content to .env from KeePass entry.'
|
||||
# Kubernetes
|
||||
printf "$column" 'save-kubeconfig-to-pass' '[ctx]' 'Save kubeconfig file in pass.'
|
||||
printf "$column" 'save-kubeconfig-to-keepass' '[ctx]' 'Save kubeconfig file in KeePass.'
|
||||
|
||||
Reference in new issue
Block a user