Skip to content

Commit b74a243

Browse files
author
Alexander Ludov
committed
feat(init): add Vite frontend service template
- added the --frontend flag and GitLab C as the default platform - implemented a Vite/TypeScript template with runtime config and PATH_PREFIX - added Docker and CI configurations for GitLab C, GitLab, and GitHub - added RSpec and Vitest coverage for generation and runtime settings
1 parent 25c20c9 commit b74a243

50 files changed

Lines changed: 4178 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
stack-service-base (0.0.99)
4+
stack-service-base (0.1.0)
55
async
66
debug
77
dotenv

lib/stack-service-base/command_init.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ def options(parser)
66
parser.on('', '--gitlab-c', 'Gitlab C CI/CD')
77
parser.on('', '--gitlab', 'Gitlab CI/CD')
88
parser.on('', '--github', 'GitHub CI/CD')
9+
parser.on('', '--frontend', 'Vite frontend service')
910
end
1011

1112
def run(obj, params, args, _extra)
1213
if params.empty? || args.empty?
1314
puts 'Usage:'
14-
puts "\tssbase init [option] <service name>"
15+
puts "\tssbase init [--frontend] [option] <service name>"
1516
puts "\tssbase init stack [option]"
1617
puts 'option: --gitlab-c, --gitlab, --github'
1718
return
@@ -23,13 +24,14 @@ def run(obj, params, args, _extra)
2324
type = :stack
2425
service_name = 'fake-service-name'
2526
else
26-
type = :project
27+
type = params[:frontend] ? :frontend : :project
2728
service_name = first_arg
2829
end
2930

3031
copy_folder type, :home
3132

32-
copy_folder type, 'gitlab-c' if params[:gitlab_c]
33+
default_platform = params.values_at(:gitlab_c, :gitlab, :github).none?
34+
copy_folder type, 'gitlab-c' if params[:gitlab_c] || default_platform
3335
copy_folder type, 'gitlab' if params[:gitlab]
3436
copy_folder type, 'github' if params[:github]
3537

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
on: { push: { branches: [main,release] } }
2+
3+
jobs:
4+
build_service_images:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v3
8+
- uses: actions/setup-node@v4
9+
with:
10+
node-version: 24.18
11+
cache: npm
12+
cache-dependency-path: src/package-lock.json
13+
- run: npm ci
14+
working-directory: src
15+
- run: npm run check
16+
working-directory: src
17+
- uses: docker/login-action@v2
18+
with: { username: '${{ secrets.DOCKER_HUB_LOGIN }}', password: '${{ secrets.DOCKER_HUB_PASSWORD }}' }
19+
- uses: docker/setup-buildx-action@v3
20+
- uses: ruby/setup-ruby@v1
21+
with: { ruby-version: 3.4.4 }
22+
- run: gem install build-labels
23+
- run: env && cd docker && build-labels -n -c docker-compose.yml $(if [ "${GITHUB_REF##*/}" = "release" ]; then echo "--full-version"; fi) github set_version to_dockerfiles to_compose | tee bake.yml
24+
env:
25+
GITHUB_RUN_NUMBER: ${{ github.run_number }}
26+
- uses: docker/bake-action@v5
27+
env: { REGISTRY_HOST: '${{ secrets.DOCKER_HUB_LOGIN }}' }
28+
with: { workdir: ./docker, files: bake.yml, push: true }
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
${service_name}:
3+
image: ${REGISTRY_HOST}/${service_name}
4+
build:
5+
context: ../src
6+
additional_contexts:
7+
docker: ../docker
8+
dockerfile: ../docker/frontend/Dockerfile
9+
ports:
10+
- "7000:8080"
11+
environment:
12+
API_BASE_URL: ${API_BASE_URL:-}
13+
BACKEND_URL: ${BACKEND_URL:-http://127.0.0.1:65535}
14+
LOG_LEVEL: ${LOG_LEVEL:-info}
15+
PATH_PREFIX: ${PATH_PREFIX:-}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
stages:
2+
- first
3+
4+
.build_block: &build_block
5+
stage: first
6+
tags: [ build ]
7+
needs: [ ]
8+
image: docker:27.5.1
9+
script:
10+
- export CI_COMMIT_TAG="${CI_COMMIT_TAG:-0.0.0}"
11+
- docker run --rm `env | grep -o '^CI_[^=]*' | sed 's/^/-e /'`
12+
-v /var/run/docker.sock:/var/run/docker.sock
13+
-v /root/.docker:/root/.docker
14+
$(docker build -q -t build/${CI_PROJECT_NAME} -f docker/Dockerfile.build .) 2>&1
15+
16+
build push:
17+
<<: *build_block
18+
19+
tests:
20+
<<: *build_block
21+
variables:
22+
CI_SKIP_PUSH: true
23+
# build-labels sets target for each service in docker-compose.yml
24+
CI_BUILD_TARGET: tests
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM ruby:3.4.4-slim-bookworm AS base
2+
RUN apt update && apt install -y --no-install-recommends bash git
3+
RUN gem install build-labels:0.0.79
4+
RUN BUILDX_VERSION=v0.20.1 COMPOSE_VERSION=v2.33.0 install-docker-static 27.5.1
5+
6+
WORKDIR /build
7+
8+
COPY . .
9+
10+
CMD ["bash", "-c", "-x", "\
11+
env && cd /build/docker && \
12+
build-labels -n -c docker-compose.yml changed gitlab set_version to_dockerfiles to_compose | tee bake.yml && \
13+
export OTEL_RESOURCE_ATTRIBUTES=service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID},project.name=${CI_PROJECT_NAME} && \
14+
export REGISTRY_HOST=$CI_REGISTRY_HOST && export BUILDX_BAKE_ENTITLEMENTS_FS=0 && \
15+
grep \"services: {}\" bake.yml || docker buildx bake -f bake.yml $([ -z \"$CI_SKIP_PUSH\" ] && echo \"--push\") && \
16+
([ \"$CI_BUILD_TARGET\" = \"tests\" ] && (docker compose -f bake.yml down && docker compose -f bake.yml up --force-recreate ) || true) \
17+
"]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
${service_name}:
3+
image: ${REGISTRY_HOST}/${service_name}/${CI_COMMIT_BRANCH}
4+
build:
5+
context: ../src
6+
additional_contexts:
7+
docker: ../docker
8+
dockerfile: ../docker/frontend/Dockerfile
9+
ports:
10+
- "7000:8080"
11+
environment:
12+
API_BASE_URL: ${API_BASE_URL:-}
13+
BACKEND_URL: ${BACKEND_URL:-http://127.0.0.1:65535}
14+
LOG_LEVEL: ${LOG_LEVEL:-info}
15+
PATH_PREFIX: ${PATH_PREFIX:-}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CI_PROJECT_NAME=${service_name}
2+
export CI_PIPELINE_ID=local
3+
export CI_PIPELINE_IID=0
4+
export CI_REGISTRY_HOST=localhost
5+
export CI_SKIP_PUSH=true
6+
7+
# -v /root/.docker:/root/.docker \
8+
docker run --rm --env-file <(env | grep ^CI_) \
9+
-v /var/run/docker.sock:/var/run/docker.sock \
10+
$(docker build -q -t build/${CI_PROJECT_NAME} -f Dockerfile.build ..) 2>&1
11+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
stages:
2+
- test
3+
- build
4+
5+
.build_block: &build_block
6+
# tags: [ build ]
7+
image: docker:27.5.1-cli
8+
services:
9+
- name: docker:27.5.1-dind
10+
alias: docker
11+
variables:
12+
DOCKER_HOST: tcp://docker:2375
13+
DOCKER_TLS_CERTDIR: ""
14+
script:
15+
- export CI_COMMIT_TAG="${CI_COMMIT_TAG:-0.0.0}"
16+
- |
17+
if [ -n "${CI_REGISTRY:-}" ] && [ -n "${CI_REGISTRY_USER:-}" ] && [ -n "${CI_REGISTRY_PASSWORD:-}" ]; then
18+
echo "${CI_REGISTRY_PASSWORD}" | docker login "${CI_REGISTRY}" -u "${CI_REGISTRY_USER}" --password-stdin
19+
fi
20+
- docker buildx create --name "${CI_PROJECT_NAME}-wrapper-builder" --driver docker-container --use || docker buildx use "${CI_PROJECT_NAME}-wrapper-builder"
21+
- docker buildx inspect --bootstrap
22+
- |
23+
docker buildx build --load \
24+
-t build/${CI_PROJECT_NAME} \
25+
-f docker/Dockerfile.build \
26+
--cache-from type=registry,ref=${CI_REGISTRY_IMAGE}/ci-wrapper:${CI_COMMIT_REF_SLUG}-cache \
27+
--cache-to type=registry,ref=${CI_REGISTRY_IMAGE}/ci-wrapper:${CI_COMMIT_REF_SLUG}-cache,mode=max \
28+
.
29+
- docker run --rm `env | grep -o '^CI_[^=]*' | sed 's/^/-e /'`
30+
-e REGISTRY_HOST=$CI_REGISTRY/$CI_PROJECT_NAMESPACE
31+
-v /var/run/docker.sock:/var/run/docker.sock
32+
-v /root/.docker:/root/.docker
33+
build/${CI_PROJECT_NAME} 2>&1
34+
35+
build push:
36+
<<: *build_block
37+
stage: build
38+
needs: [ tests ]
39+
40+
tests:
41+
<<: *build_block
42+
stage: test
43+
variables:
44+
DOCKER_HOST: tcp://docker:2375
45+
DOCKER_TLS_CERTDIR: ""
46+
CI_SKIP_PUSH: true
47+
# build-labels sets target for each service in docker-compose.yml
48+
CI_BUILD_TARGET: tests
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM ruby:3.4.4-slim-bookworm AS base
2+
RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates curl git tar \
3+
&& rm -rf /var/lib/apt/lists/*
4+
RUN gem install build-labels:0.0.79
5+
RUN BUILDX_VERSION=v0.20.1 COMPOSE_VERSION=v2.33.0 install-docker-static 27.5.1
6+
7+
WORKDIR /build
8+
9+
COPY .. .
10+
11+
CMD ["bash", "-euo", "pipefail", "-c", "\
12+
cd /build/docker; \
13+
if [ -n \"${CI_REGISTRY:-}\" ] && [ -n \"${CI_REGISTRY_USER:-}\" ] && [ -n \"${CI_REGISTRY_PASSWORD:-}\" ]; then \
14+
echo \"$CI_REGISTRY_PASSWORD\" | docker login \"$CI_REGISTRY\" -u \"$CI_REGISTRY_USER\" --password-stdin; \
15+
fi; \
16+
build-labels -n -c docker-compose.yml changed gitlab set_version cache to_dockerfiles to_compose | tee bake.yml; \
17+
export OTEL_RESOURCE_ATTRIBUTES=\"service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID:-local},project.name=${service_name}\"; \
18+
export REGISTRY_HOST=\"${REGISTRY_HOST:-${CI_REGISTRY_HOST:-${CI_REGISTRY_IMAGE:-}}}\"; \
19+
: \"${REGISTRY_HOST:?REGISTRY_HOST, CI_REGISTRY_IMAGE, or CI_REGISTRY_HOST is required}\"; \
20+
export BUILDX_BAKE_ENTITLEMENTS_FS=0; \
21+
if grep -q \"services: {}\" bake.yml; then \
22+
echo \"No changed services to build.\"; \
23+
exit 0; \
24+
fi; \
25+
docker buildx create --name \"${service_name}-builder\" --driver docker-container --use || docker buildx use \"${service_name}-builder\"; \
26+
docker buildx inspect --bootstrap; \
27+
if [ -n \"${CI_SKIP_PUSH:-}\" ]; then \
28+
docker buildx bake --load --allow=fs.read=../src -f bake.yml; \
29+
else \
30+
docker buildx bake --push --allow=fs.read=../src -f bake.yml; \
31+
fi; \
32+
if [ \"${CI_BUILD_TARGET:-}\" = \"tests\" ]; then \
33+
docker compose -f bake.yml down --remove-orphans; \
34+
docker compose -f bake.yml up --no-build --force-recreate --abort-on-container-failure; \
35+
fi \
36+
"]

0 commit comments

Comments
 (0)