Skip to content

Commit fbe5d46

Browse files
authored
Merge pull request #1 from lgdevlop/refactor-image-generation
📚 Improve project README with DevContainer features and Docker image workflow
2 parents 3d8fc5f + 2fb148c commit fbe5d46

27 files changed

Lines changed: 4001 additions & 510 deletions

.config_shell/.sh_functions

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,104 @@
55
#######################################################################################################################
66

77

8+
#######################################################################################################################
9+
#
10+
# histdb autosuggest
11+
12+
_zsh_autosuggest_strategy_histdb_top_here() {
13+
local query="select commands.argv from
14+
history left join commands on history.command_id = commands.rowid
15+
left join places on history.place_id = places.rowid
16+
where places.dir LIKE '$(sql_escape $PWD)%'
17+
and commands.argv LIKE '$(sql_escape $1)%'
18+
group by commands.argv order by count(*) desc limit 1"
19+
suggestion=$(_histdb_query "$query")
20+
}
21+
22+
_zsh_autosuggest_strategy_histdb_top() {
23+
local query="
24+
select commands.argv from history
25+
left join commands on history.command_id = commands.rowid
26+
left join places on history.place_id = places.rowid
27+
where commands.argv LIKE '$(sql_escape $1)%'
28+
group by commands.argv, places.dir
29+
order by places.dir != '$(sql_escape $PWD)', count(*) desc
30+
limit 1
31+
"
32+
suggestion=$(_histdb_query "$query")
33+
}
34+
35+
# Query to pull in the most recent command if anything was found similar
36+
# in that directory. Otherwise pull in the most recent command used anywhere
37+
# Give back the command that was used most recently
38+
_zsh_autosuggest_strategy_histdb_top_fallback() {
39+
local query="
40+
select commands.argv from
41+
history left join commands on history.command_id = commands.rowid
42+
left join places on history.place_id = places.rowid
43+
where places.dir LIKE
44+
case when exists(select commands.argv from history
45+
left join commands on history.command_id = commands.rowid
46+
left join places on history.place_id = places.rowid
47+
where places.dir LIKE '$(sql_escape $PWD)%'
48+
AND commands.argv LIKE '$(sql_escape $1)%')
49+
then '$(sql_escape $PWD)%'
50+
else '%'
51+
end
52+
and commands.argv LIKE '$(sql_escape $1)%'
53+
group by commands.argv
54+
order by places.dir LIKE '$(sql_escape $PWD)%' desc,
55+
history.start_time desc
56+
limit 1"
57+
suggestion=$(_histdb_query "$query")
58+
}
59+
60+
show_local_history() {
61+
limit="${1:-10}"
62+
local query="
63+
select history.start_time, commands.argv
64+
from history left join commands on history.command_id = commands.rowid
65+
left join places on history.place_id = places.rowid
66+
where places.dir LIKE '$(sql_escape $PWD)%'
67+
order by history.start_time desc
68+
limit $limit
69+
"
70+
results=$(_histdb_query "$query")
71+
echo "$results"
72+
}
73+
74+
search_local_history() {
75+
show_local_history 100 | grep "$1"
76+
}
77+
78+
# It can be used to find a command in the whole history
79+
find_command_history() {
80+
limit="${2:-10}"
81+
local query="
82+
select commands.argv
83+
from history left join commands on history.command_id = commands.rowid
84+
left join places on history.place_id = places.rowid
85+
where commands.argv LIKE '$(sql_escape $1)%'
86+
order by history.start_time desc
87+
limit 10
88+
"
89+
# results=$(_histdb_query ".header on" ".mode column" "$query")
90+
results=$(_histdb_query "$query")
91+
echo "$results"
92+
}
93+
94+
#######################################################################################################################
95+
96+
extract_release_version() {
97+
echo $@ | sed -nre 's/^[^0-9]*(([0-9]+\.)*[0-9]+).*/\1/p'
98+
}
99+
100+
has_program() {
101+
if ! command -v "$1" &> /dev/null; then
102+
echo false
103+
else
104+
echo true
105+
fi
106+
}
107+
8108
#######################################################################################################################

.config_shell/.sh_key_hooks

Lines changed: 0 additions & 29 deletions
This file was deleted.

.config_shell/.sh_paths

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,28 @@
44
#
55
#######################################################################################################################
66

7+
# Path to your zsh installation.
8+
export ZSH="$HOME/.zsh"
9+
710
# Path for executables
811
export PATH="$PATH:$HOME/bin"
912
export PATH="$PATH:/usr/local/bin"
1013

1114
# Path for NodeJs executables
1215
export PATH="$PATH:$HOME/.yarn/bin/"
1316

17+
# Path for others executables
18+
export PATH="$PATH:$HOME/.local/bin"
19+
20+
# Java setup
21+
# export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
22+
# export PATH=$JAVA_HOME/bin:$PATH
23+
24+
# Maven setup
25+
export MAVEN_HOME="$HOME/.maven/default"
26+
export PATH="$MAVEN_HOME/bin:$PATH"
27+
28+
# Add fzf to PATH
29+
export PATH="$HOME/.fzf/bin:$PATH"
30+
1431
#######################################################################################################################

.github/workflows/build.yml

Lines changed: 107 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,121 @@
1-
name: CI/CD Workflow
1+
name: Manual Docker Image Build and Push (Node / Node+Java)
22

33
on:
4-
push:
5-
branches:
6-
- master
7-
paths:
8-
- 'image-tag'
4+
workflow_dispatch:
5+
inputs:
6+
image_tag:
7+
description: "Debian base tag (e.g. bullseye, bookworm)"
8+
required: true
9+
default: "bullseye"
10+
type: string
11+
include_java:
12+
description: "Include Java + Maven in the image?"
13+
required: false
14+
default: "false"
15+
type: choice
16+
options:
17+
- "true"
18+
- "false"
19+
nvm_version:
20+
description: "NVM version to install"
21+
required: false
22+
default: "0.39.7"
23+
type: string
24+
node_version:
25+
description: "Node.js version to install"
26+
required: true
27+
default: "22.1.0"
28+
type: string
29+
yarn_version:
30+
description: "Yarn version to install"
31+
required: false
32+
default: "1.22.22"
33+
type: string
34+
docker_gid:
35+
description: "GID of the 'docker' group on the host (used to access docker.sock)"
36+
required: false
37+
default: "1001"
38+
type: string
39+
java_version:
40+
description: "Java (OpenJDK) version to install (if Java enabled)"
41+
required: false
42+
default: "17"
43+
type: string
44+
maven_version:
45+
description: "Maven version to install (if Java enabled)"
46+
required: false
47+
default: "3.9.6"
48+
type: string
49+
use_cache:
50+
description: "Use Docker cache?"
51+
required: false
52+
default: "true"
53+
type: choice
54+
options:
55+
- "true"
56+
- "false"
57+
update_latest:
58+
description: "Also tag and push as 'latest'?"
59+
required: false
60+
default: "false"
61+
type: choice
62+
options:
63+
- "true"
64+
- "false"
965

1066
jobs:
11-
test:
12-
name: Build and push image to dockerhub
67+
build_and_push:
68+
name: Build and Push Docker Image
69+
if: github.actor == 'lgdevlop'
1370
runs-on: ubuntu-latest
14-
steps:
15-
- name: Checkout master
16-
uses: actions/checkout@v2
17-
18-
- name: Setup Docker Buildx
19-
id: buildx
20-
uses: docker/setup-buildx-action@v1
21-
22-
# - name: Cache Docker layers
23-
# uses: actions/cache@v2
24-
# with:
25-
# path: /tmp/.buildx-cache
26-
# key: ${{ runner.os }}-buildx-${{ github.sha }}
27-
# restore-keys: |
28-
# ${{ runner.os }}-buildx-
2971

30-
- name: Login to DockerHub
31-
uses: docker/login-action@v1
32-
with:
33-
username: ${{ secrets.DOCKERHUB_USERNAME }}
34-
password: ${{ secrets.DOCKERHUB_TOKEN }}
72+
steps:
73+
- name: 📥 Checkout repository
74+
uses: actions/checkout@v4
3575

36-
- name: Set environment variable
76+
- name: 🧠 Select Dockerfile template
77+
id: choose_template
3778
run: |
38-
echo "image_tag=$(cat image-tag)" >> $GITHUB_ENV
79+
if [[ "${{ inputs.include_java }}" == "true" ]]; then
80+
echo "TEMPLATE=Dockerfile.debian.node-java.template" >> $GITHUB_ENV
81+
else
82+
echo "TEMPLATE=Dockerfile.debian.node.template" >> $GITHUB_ENV
83+
fi
3984
40-
# - name: Show environment variable
41-
# run: |
42-
# echo "Image tag: ${{ env.image_tag }}"
85+
- name: 🛠️ Setup Docker Buildx
86+
uses: docker/setup-buildx-action@v3
4387

44-
- name: Set node image on Dockerfile
45-
run: |
46-
sed 's|my-docker-tag|node:'"${{ env.image_tag }}"'|g' Dockerfile > dockerfile.image
88+
- name: 💾 Restore Docker cache (if enabled)
89+
if: inputs.use_cache == 'true'
90+
uses: actions/cache@v4
91+
with:
92+
path: /tmp/.buildx-cache
93+
key: ${{ runner.os }}-buildx-${{ github.sha }}
94+
restore-keys: |
95+
${{ runner.os }}-buildx-
4796
48-
# - name: Test image build
49-
# uses: docker/build-push-action@v2
50-
# with:
51-
# no-cache: true
52-
# context: ./
53-
# file: ./dockerfile.image
54-
# push: false
55-
# tags: ${{ secrets.DOCKERHUB_USERNAME }}/node-dev/${{ env.image_tag }}
97+
- name: 🔐 Login to DockerHub
98+
uses: docker/login-action@v3
99+
with:
100+
username: ${{ secrets.DOCKERHUB_USERNAME }}
101+
password: ${{ secrets.DOCKERHUB_TOKEN }}
56102

57-
- name: Push image to dockerhub
58-
id: docker_build
59-
uses: docker/build-push-action@v2
103+
- name: 🏗️ Build and Push Docker image
104+
uses: docker/build-push-action@v5
60105
with:
61-
context: ./
62-
file: ./dockerfile.image
106+
context: .
107+
file: ${{ env.TEMPLATE }}
63108
push: true
64-
tags: ${{ secrets.DOCKERHUB_USERNAME }}/node-dev:${{ env.image_tag }}
65-
66-
# deploy:
67-
# name: Push image to dockerhub
68-
# needs: test
69-
# runs-on: ubuntu-latest
70-
# steps:
71-
# - name: Set environment variable
72-
# run: |
73-
# echo "image_tag=$(cat image-tag)" >> $GITHUB_ENV
74-
75-
# - name: Show Dockerfile
76-
# run: |
77-
# cat dockerfile.image
78-
79-
# # - name: Build and push
80-
# # id: docker_build
81-
# # uses: docker/build-push-action@v2
82-
# # with:
83-
# # context: ./
84-
# # file: ./dockerfile.image
85-
# # push: true
86-
# # tags: lgdevlop/node-dev/${{ env.image_tag }}
109+
tags: |
110+
${{ secrets.DOCKERHUB_USERNAME }}/node-dev:${{ inputs.node_version }}-${{ inputs.image_tag }}
111+
${{ inputs.update_latest == 'true' && format('{0}/node-dev:latest', secrets.DOCKERHUB_USERNAME) || '' }}
112+
build-args: |
113+
IMAGE_TAG=${{ inputs.image_tag }}
114+
NVM_VERSION=${{ inputs.nvm_version }}
115+
NODE_VERSION=${{ inputs.node_version }}
116+
YARN_VERSION=${{ inputs.yarn_version }}
117+
JAVA_VERSION=${{ inputs.java_version }}
118+
MAVEN_VERSION=${{ inputs.maven_version }}
119+
DOCKER_GID=${{ inputs.docker_gid }}
120+
cache-from: ${{ inputs.use_cache == 'true' && 'type=gha' || '' }}
121+
cache-to: ${{ inputs.use_cache == 'true' && 'type=gha,mode=max' || '' }}

.histdb/zsh-history.db

44 KB
Binary file not shown.

0 commit comments

Comments
 (0)