Skip to content

Commit

Permalink
🔥 fix buildsh
Browse files Browse the repository at this point in the history
  • Loading branch information
xiagw committed Jul 30, 2023
1 parent f62a324 commit d5cff02
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 28 deletions.
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
FROM ubuntu:20.04
FROM ubuntu:22.04

WORKDIR /runner

COPY . /runner/

RUN set -x \
# && touch Dockerfile composer.json package.json pom.xml requirements.txt \
&& sed -i -e '/=false/s/false/true/g' /runner/conf/example-deploy.env \
&& sed -i -e '/ENV_INSTALL_JMETER=/s/true/false/' /runner/conf/example-deploy.env \
&& chmod +x /runner//deploy.sh \
&& /runner/deploy.sh --github-action
RUN set -xe; \
# touch Dockerfile composer.json package.json pom.xml requirements.txt; \
mkdir data; \
cp -vf conf/example-deploy.env conf/conf/deploy.env; \
sed -i -e '/=false/s/false/true/g' data/deploy.env; \
sed -i -e '/ENV_INSTALL_JMETER=/s/true/false/' data/deploy.env; \
chmod +x deploy.sh; \
deploy.sh --github-action
10 changes: 7 additions & 3 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1144,24 +1144,28 @@ _setup_gitlab_vars() {

_probe_langs() {
_msg step "[langs] probe language"
for f in pom.xml composer.json package.json requirements.txt {README,readme}.{md,txt}; do
for f in pom.xml {composer,package}.json requirements.txt {README,readme}.{md,txt}; do
[[ -f "${gitlab_project_dir}"/${f} ]] || continue
case $f in
composer.json)
echo "Found composer.json"
project_lang=php
break
;;
package.json)
echo "Found package.json"
project_lang=node
break
;;
pom.xml)
echo "Found pom.xml"
project_lang=java
break
;;
requirements.txt)
echo "Found requirements.txt"
project_lang=python
break
;;
*)
project_lang=${project_lang:-$(awk -F= '/^project_lang/ {print $2}' "${gitlab_project_dir}"/${f} | head -n 1)}
Expand Down Expand Up @@ -1391,7 +1395,7 @@ _set_args() {
}

main() {
_msg time "[BEGIN]"
_msg time "[deploy] BEGIN"
## Process parameters / 处理传入的参数
_set_args "$@"

Expand Down Expand Up @@ -1628,7 +1632,7 @@ main() {
_deploy_notify
fi

_msg time "[END]"
_msg time "[deploy] END"
## deploy result: 0 成功, 1 失败
return ${deploy_result:-0}
}
Expand Down
6 changes: 3 additions & 3 deletions langs/build.docker.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

_msg step "build image [docker]..."
_msg step "[build] docker build image"

DOCKER_BUILDKIT=1 docker build ${quiet_flag} \
docker build ${quiet_flag} \
--tag "${ENV_DOCKER_REGISTRY}/${ENV_DOCKER_REPO}:${image_tag}" \
--build-arg IN_CHINA="${ENV_IN_CHINA:-false}" \
"${gitlab_project_dir}"

_msg time "end docker build."
_msg time "[build] end docker build"
13 changes: 7 additions & 6 deletions langs/build.java.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
# shellcheck disable=2154

path_for_rsync="jar_file"
MVN_PROFILE="${gitlab_project_branch}"
jars_path="jars"
maven_cache="${me_path_data}"/cache.maven

if [[ -f "$gitlab_project_dir/build.gradle" ]]; then
Expand All @@ -29,16 +29,17 @@ else
--activate-profiles "$MVN_PROFILE" $MVN_SET
fi

[ -d "$gitlab_project_dir/$path_for_rsync" ] || mkdir "$gitlab_project_dir/${path_for_rsync}"
[ -d "$gitlab_project_dir/$jars_path" ] || mkdir "$gitlab_project_dir/${jars_path}"

find "${gitlab_project_dir}" -path "${path_for_rsync}" -prune -o -type f \
find "${gitlab_project_dir}" -path "${jars_path}" -prune -o -type f \
-regextype egrep -iregex '.*SNAPSHOT.*\.(jar|war)' \
-exec rsync -a --exclude='framework*' --exclude='gdp-module*' --exclude='sdk*.jar' --exclude='core*.jar' {} "$path_for_rsync/" \;
-exec rsync -a --exclude='framework*' --exclude='gdp-module*' --exclude='sdk*.jar' --exclude='core*.jar' {} "$jars_path/" \;

## copy *.yml
if [[ "${exec_deploy_k8s:-0}" -ne 1 ]]; then
find "${gitlab_project_dir}" -path "${path_for_rsync}" -prune -o -type f \
find "${gitlab_project_dir}" -path "${jars_path}" -prune -o -type f \
-regextype egrep -iregex ".*resources.*${gitlab_project_branch}.*\.(yml)" \
-exec rsync -a {} "$path_for_rsync/" \;
-exec rsync -a {} "$jars_path/" \;
fi

_msg stepend "[build] java build"
15 changes: 6 additions & 9 deletions langs/build.php.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
file_json="${gitlab_project_dir}/composer.json"
file_json_md5="$gitlab_project_path/$env_namespace/$(md5sum "$file_json" | awk '{print $1}')"
if grep -q "$file_json_md5" "${me_log}"; then
echo "The same checksum for ${file_json}, skip composer install."
_msg time "The same checksum for ${file_json}, skip composer install."
else
echo "New checksum for ${file_json}, run composer install."
_msg time "New checksum for ${file_json}, run composer install."
COMPOSER_INSTALL=1
fi
if [ ! -d "${gitlab_project_dir}/vendor" ]; then
echo "Not found ${gitlab_project_dir}/vendor, run composer install."
_msg time "Not found ${gitlab_project_dir}/vendor, run composer install."
COMPOSER_INSTALL=1
fi

if [ -f "$gitlab_project_dir"/custom.build.sh ]; then
echo "Found $gitlab_project_dir/custom.build.sh, run it"
_msg time "Found $gitlab_project_dir/custom.build.sh, run it"
bash "$gitlab_project_dir"/custom.build.sh
return
fi
Expand All @@ -29,11 +29,8 @@ if [[ "${COMPOSER_INSTALL:-0}" -eq 1 ]]; then
# fi
# rm -rf "${gitlab_project_dir}"/vendor
# shellcheck disable=2015
$docker_run -v "$gitlab_project_dir:/app" \
-w /app "${build_image_from:-composer}" \
bash -c "composer install ${quiet_flag}" &&
echo "$file_json_md5 ${file_json}" >>"${me_log}" || true
[ -d "$gitlab_project_dir"/vendor ] && chown -R 1000:1000 "$gitlab_project_dir"/vendor
$docker_run -v "$gitlab_project_dir:/app" -w /app "${build_image_from:-composer}" bash -c "composer install ${quiet_flag}" && echo "$file_json_md5 ${file_json}" >>"${me_log}" || true
[ -d "$gitlab_project_dir"/vendor ] && chown -R "$(id -u):$(id -g)" "$gitlab_project_dir"/vendor
_msg stepend "[build] php composer install"
else
_msg time "skip php composer install."
Expand Down

0 comments on commit d5cff02

Please sign in to comment.