Improvements on image building.

This commit is contained in:
Andrey Antukh 2020-12-12 13:29:17 +01:00
parent 4903d26038
commit f4157ba0e5
3 changed files with 66 additions and 33 deletions

View file

@ -201,9 +201,3 @@ gulp.task("dist:copy", function() {
return gulp.src(paths.output + "**/*") return gulp.src(paths.output + "**/*")
.pipe(gulp.dest(paths.dist)); .pipe(gulp.dest(paths.dist));
}); });
gulp.task("dist:gzip", function() {
return gulp.src(`${paths.dist}**/!(*.gz|*.br|*.jpg|*.png)`)
.pipe(gulpGzip({gzipOptions: {level: 9}}))
.pipe(gulp.dest(paths.dist));
});

View file

@ -19,4 +19,3 @@ npx shadow-cljs release main --config-merge "{:release-version \"${TAG}\"}" $SHA
npx gulp build || exit 1; npx gulp build || exit 1;
npx gulp dist:clean || exit 1; npx gulp dist:clean || exit 1;
npx gulp dist:copy || exit 1; npx gulp dist:copy || exit 1;
npx gulp dist:gzip || exit 1;

View file

@ -7,7 +7,8 @@ export DEVENV_PNAME="penpotdev";
export CURRENT_USER_ID=$(id -u); export CURRENT_USER_ID=$(id -u);
export CURRENT_VERSION=$(git describe --tags); export CURRENT_VERSION=$(git describe --tags);
export CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD); export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
export CURRENT_HASH=$(git rev-parse --short HEAD);
function build-devenv { function build-devenv {
echo "Building development image $DEVENV_IMGNAME:latest..." echo "Building development image $DEVENV_IMGNAME:latest..."
@ -95,14 +96,21 @@ function build-bundle {
mv ./backend/target/dist ./bundle/backend mv ./backend/target/dist ./bundle/backend
mv ./exporter/target ./bundle/exporter mv ./exporter/target ./bundle/exporter
local version="$CURRENT_VERSION";
local name="penpot-$CURRENT_VERSION"; local name="penpot-$CURRENT_VERSION";
echo $CURRENT_VERSION > ./bundle/version.txt
sed -i -re "s/\%version\%/$CURRENT_VERSION/g" ./bundle/frontend/index.html; if [ $CURRENT_BRANCH != "main" ]; then
sed -i -re "s/\%version\%/$CURRENT_VERSION/g" ./bundle/backend/main/app/config.clj; local ncommits=$(git rev-list --count HEAD);
version="$CURRENT_BRANCH-$ncommits-$CURRENT_HASH";
name="penpot-$CURRENT_BRANCH";
fi;
echo $version > ./bundle/version.txt
sed -i -re "s/\%version\%/$version/g" ./bundle/frontend/index.html;
sed -i -re "s/\%version\%/$version/g" ./bundle/backend/main/app/config.clj;
local generate_tar=${PENPOT_BUILD_GENERATE_TAR:-"true"}; local generate_tar=${PENPOT_BUILD_GENERATE_TAR:-"true"};
if [ $generate_tar == "true" ]; then if [ $generate_tar == "true" ]; then
pushd bundle/ pushd bundle/
tar -cvf ../$name.tar *; tar -cvf ../$name.tar *;
@ -117,48 +125,76 @@ function build-bundle {
} }
function build-image { function build-image {
set -ex;
local image=$1; local image=$1;
local version=$2;
pushd ./docker/images;
local docker_image="$ORGANIZATION/$image"; local docker_image="$ORGANIZATION/$image";
docker build -t $docker_image:$CURRENT_VERSION -f Dockerfile.$image .;
set -x
pushd ./docker/images;
docker buildx build --platform linux/amd64 -t $docker_image:$version -f Dockerfile.$image .;
# docker buildx build --platform linux/arm64 -t $docker_image:$version-arm64 .;
popd; popd;
} }
function build-images { function build-images {
local version="$CURRENT_VERSION";
local bundle_file="penpot-$CURRENT_VERSION.tar.xz"; local bundle_file="penpot-$CURRENT_VERSION.tar.xz";
if [ $CURRENT_BRANCH != "main" ]; then
version="$CURRENT_BRANCH";
bundle_file="penpot-$CURRENT_BRANCH.tar.xz";
fi;
if [ ! -f $bundle_file ]; then if [ ! -f $bundle_file ]; then
echo "File '$bundle_file' does not exists."; echo "File '$bundle_file' does not exists.";
exit 1; exit 1;
fi fi
rm -rf ./docker/images/bundle;
mkdir -p ./docker/images/bundle;
local bundle_file_path=`readlink -f $bundle_file`; local bundle_file_path=`readlink -f $bundle_file`;
echo "Building docker image from: $bundle_file_path."; echo "Building docker image from: $bundle_file_path.";
rm -rf ./docker/images/bundle;
mkdir -p ./docker/images/bundle;
pushd ./docker/images/bundle; pushd ./docker/images/bundle;
tar xvf $bundle_file_path; tar xvf $bundle_file_path;
popd popd
build-image "backend"; build-image "backend" $version;
build-image "frontend"; build-image "frontend" $version;
build-image "exporter"; build-image "exporter" $version;
} }
function publish-snapshot { function publish-latest-images {
set -x if [ $CURRENT_BRANCH != "main" ]; then
docker tag $ORGANIZATION/frontend:$CURRENT_VERSION $ORGANIZATION/frontend:$CURRENT_GIT_BRANCH echo "Latest image can only be build from main branch.";
docker tag $ORGANIZATION/backend:$CURRENT_VERSION $ORGANIZATION/backend:$CURRENT_GIT_BRANCH exit 1;
docker tag $ORGANIZATION/exporter:$CURRENT_VERSION $ORGANIZATION/exporter:$CURRENT_GIT_BRANCH fi;
docker push $ORGANIZATION/frontend:$CURRENT_GIT_BRANCH; set -x
docker push $ORGANIZATION/backend:$CURRENT_GIT_BRANCH;
docker push $ORGANIZATION/exporter:$CURRENT_GIT_BRANCH; docker tag $ORGANIZATION/frontend:$CURRENT_VERSION $ORGANIZATION/frontend:latest;
docker tag $ORGANIZATION/backend:$CURRENT_VERSION $ORGANIZATION/backend:latest;
docker tag $ORGANIZATION/exporter:$CURRENT_VERSION $ORGANIZATION/exporter:latest;
docker push $ORGANIZATION/frontend:$CURRENT_VERSION;
docker push $ORGANIZATION/backend:$CURRENT_VERSION;
docker push $ORGANIZATION/exporter:$CURRENT_VERSION;
docker push $ORGANIZATION/frontend:latest;
docker push $ORGANIZATION/backend:latest;
docker push $ORGANIZATION/exporter:latest;
}
function publish-snapshot-images {
set -x
docker tag $ORGANIZATION/frontend:$CURRENT_VERSION $ORGANIZATION/frontend:$CURRENT_BRANCH
docker tag $ORGANIZATION/backend:$CURRENT_VERSION $ORGANIZATION/backend:$CURRENT_BRANCH
docker tag $ORGANIZATION/exporter:$CURRENT_VERSION $ORGANIZATION/exporter:$CURRENT_BRANCH
docker push $ORGANIZATION/frontend:$CURRENT_BRANCH;
docker push $ORGANIZATION/backend:$CURRENT_BRANCH;
docker push $ORGANIZATION/exporter:$CURRENT_BRANCH;
} }
function usage { function usage {
@ -245,8 +281,12 @@ case $1 in
build-images; build-images;
;; ;;
publish-snapshot) publish-snapshot-images)
publish-snapshot ${@:2} publish-snapshot-images;
;;
publish-latest-images)
publish-latest-images;
;; ;;
*) *)