forked from illacloud/illa-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
version: 2.1 | ||
jobs: | ||
build: | ||
working_directory: ~/project | ||
docker: | ||
- image: docker:17.05.0-ce-git | ||
resource_class: xlarge | ||
steps: | ||
- checkout | ||
- setup_remote_docker | ||
- run: | ||
name: Clone repo | ||
command: | | ||
git clone -b ${CIRCLE_BRANCH} https://github.com/illacloud/illa-builder | ||
git submodule init | ||
git submodule update | ||
- restore_cache: | ||
keys: | ||
- v1-{{ .Branch }} | ||
paths: | ||
- /caches/illa-builder-frontend.tar | ||
- run: | ||
name: Load Docker image layer cache | ||
command: | | ||
set +o pipefail | ||
docker load -i /illa-builder-frontend.tar | true | ||
- run: | ||
name: Build application Docker image | ||
command: | | ||
docker build --cache-from=illa-builder-frontend -f Dockerfile -t illa-builder-frontend . | ||
- run: | ||
name: Save Docker image layer cache | ||
command: | | ||
mkdir -p /caches | ||
docker save -o /caches/illa-builder-frontend.tar illa-builder-frontend | ||
- save_cache: | ||
key: v1-{{ .Branch }}-{{ epoch }} | ||
paths: | ||
- /caches/illa-builder-frontend.tar | ||
- deploy: | ||
name: Push application Docker image | ||
command: | | ||
docker login -u $DOCKER_LOGIN -p $DOCKER_PWD | ||
docker tag illa-builder-frontend "illasoft/illa-builder-frontend:${CIRCLE_BRANCH}" | ||
docker push "illasoft/illa-builder-frontend:${CIRCLE_BRANCH}" | ||
workflows: | ||
illa-builder-frontend: | ||
when: | ||
or: | ||
- equal: [develop, << pipeline.git.branch >>] | ||
jobs: | ||
- build: | ||
context: | ||
- org-global |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# ------------------ | ||
# build illa-fontend | ||
FROM node:18-bullseye as builder-for-frontend | ||
|
||
## clone frontend | ||
WORKDIR /opt/illa/illa-builder-frontend | ||
RUN cd /opt/illa/illa-builder-frontend | ||
RUN pwd | ||
|
||
ADD ./* ./ | ||
|
||
RUN npm install -g pnpm | ||
RUN whereis pnpm | ||
RUN whereis node | ||
|
||
## build | ||
|
||
RUN pnpm install | ||
RUN pnpm build-cloud | ||
|
||
|
||
# ------------------- | ||
# build runner images | ||
FROM nginx:stable-alpine as runner | ||
RUN ls -alh /etc/nginx/ | ||
|
||
RUN apk add --no-cache \ | ||
bash \ | ||
sed | ||
|
||
|
||
## copy frontend | ||
COPY nginx.conf /etc/nginx/nginx.conf | ||
COPY illa-builder-frontend.conf /etc/nginx/conf.d/illa-builder-frontend.conf | ||
COPY --from=builder-for-frontend /opt/illa/illa-builder-frontend/apps/builder/dist/index.html /opt/illa/illa-builder-frontend/index.html | ||
COPY --from=builder-for-frontend /opt/illa/illa-builder-frontend/apps/builder/dist/assets /opt/illa/illa-builder-frontend/assets | ||
RUN rm /etc/nginx/conf.d/default.conf | ||
|
||
# test nginx | ||
RUN nginx -t | ||
|
||
|
||
|
||
RUN ls -alh /opt/illa/illa-builder-frontend/ | ||
|
||
## add main scripts | ||
COPY illa-builder-frontend-main.sh /opt/illa/ | ||
COPY illa-builder-frontend-config-init.sh /opt/illa/ | ||
RUN chmod +x /opt/illa/illa-builder-frontend-main.sh | ||
RUN chmod +x /opt/illa/illa-builder-frontend-config-init.sh | ||
|
||
# HEALTHCHECK --interval=5s --timeout=3s CMD curl -fs http://127.0.0.1:80/status?src=docker_health_check -H"Host:localhost" || exit 1 | ||
|
||
# run | ||
EXPOSE 80 | ||
CMD ["/opt/illa/illa-builder-frontend-main.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
# check to see if this file is being run or sourced from another script | ||
_is_sourced() { | ||
# https://unix.stackexchange.com/a/215279 | ||
[ "${#FUNCNAME[@]}" -ge 2 ] \ | ||
&& [ "${FUNCNAME[0]}" = '_is_sourced' ] \ | ||
&& [ "${FUNCNAME[1]}" = 'source' ] | ||
} | ||
|
||
|
||
_main() { | ||
|
||
echo | ||
echo 'config init.' | ||
echo | ||
|
||
# replace frontend repo | ||
if [ ! -n "$API_SERVER_ADDRESS" ]; then | ||
echo "API_SERVER_ADDRESS not defined, skip." | ||
else | ||
sed -i "s/localhost/$API_SERVER_ADDRESS/g" /opt/illa/illa-builder-frontend/assets/*.js | ||
fi | ||
|
||
if [ ! -n "$RELEASE_VERSION" ]; then | ||
echo "RELEASE_VERSION not defined, skip." | ||
else | ||
sed -i "s#<head>#<head><meta release-version=\"$RELEASE_VERSION\" />#g" /opt/illa/illa-builder-frontend/index.html | ||
fi | ||
|
||
if [ ! -n "$CLOUD_PATH" ]; then | ||
echo "CLOUD_API_PATH not defined, skip." | ||
else | ||
sed -i "s#CLOUD_PATH#$CLOUD_PATH#g" /opt/illa/illa-builder-frontend/assets/*.js | ||
fi | ||
|
||
if [ ! -n "$CLOUD_API_PATH" ]; then | ||
echo "CLOUD_API_PATH not defined, skip." | ||
else | ||
sed -i "s/CLOUD_API_PATH/$CLOUD_API_PATH/g" /opt/illa/illa-builder-frontend/assets/*.js | ||
fi | ||
|
||
|
||
if [ ! -n "$BUILDER_PATH" ]; then | ||
echo "BUILDER_PATH not defined, skip." | ||
else | ||
sed -i "s/BUILDER_PATH/$BUILDER_PATH/g" /opt/illa/illa-builder-frontend/assets/*.js | ||
fi | ||
|
||
|
||
|
||
echo | ||
echo 'config init done.' | ||
echo | ||
|
||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
if ! _is_sourced; then | ||
_main "$@" | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
/opt/illa/illa-builder-frontend-config-init.sh | ||
|
||
nginx & | ||
|
||
# loop | ||
while true; do | ||
sleep 1; | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
server { | ||
listen 80; | ||
server_name localhost; | ||
access_log /dev/stdout; | ||
error_log /dev/stderr; | ||
root /opt/illa/illa-builder-frontend/; | ||
index index.html; | ||
gzip on; | ||
|
||
proxy_ssl_server_name on; | ||
proxy_set_header Upgrade $http_upgrade; | ||
proxy_set_header Connection "upgrade"; | ||
proxy_set_header X-Forwarded-Proto $scheme; | ||
proxy_set_header X-Forwarded-Host $host; | ||
proxy_set_header Accept-Encoding ""; | ||
|
||
sub_filter_once off; | ||
location / { | ||
try_files $uri $uri/ /index.html; | ||
expires -1; | ||
} | ||
|
||
location /assets { | ||
expires 1y; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
user nginx; | ||
worker_processes 1; | ||
|
||
error_log /var/log/nginx/error.log warn; | ||
pid /var/run/nginx.pid; | ||
|
||
events { | ||
worker_connections 1024; | ||
} | ||
|
||
|
||
http { | ||
include /etc/nginx/mime.types; | ||
default_type application/octet-stream; | ||
|
||
log_format main '"$time_local" client=$remote_addr ' | ||
'method=$request_method request="$request" ' | ||
'request_length=$request_length ' | ||
'status=$status bytes_sent=$bytes_sent ' | ||
'body_bytes_sent=$body_bytes_sent ' | ||
'referer=$http_referer ' | ||
'http_x_forwarded_for=$http_x_forwarded_for ' | ||
'user_agent="$http_user_agent" ' | ||
'upstream_addr=$upstream_addr ' | ||
'upstream_status=$upstream_status ' | ||
'request_time=$request_time ' | ||
'upstream_response_time=$upstream_response_time ' | ||
'upstream_connect_time=$upstream_connect_time ' | ||
'upstream_header_time=$upstream_header_time'; | ||
|
||
access_log /var/log/nginx/access.log main; | ||
|
||
sendfile on; | ||
|
||
keepalive_timeout 65; | ||
|
||
include /etc/nginx/conf.d/*.conf; | ||
} |