Prechádzať zdrojové kódy

Add priv/build directory

theenglishway (time) 4 rokov pred
rodič
commit
28817628e5

+ 20 - 0
priv/build/build.sh

@@ -0,0 +1,20 @@
+#!/bin/bash
+# Build a project for production in the form of a release
+
+set -euo pipefail
+
+MIX_ENV=${MIX_ENV-prod}
+
+export MIX_ENV=$MIX_ENV
+
+# Build static assets
+npm --prefix ./assets ci --progress=false --no-audit --loglevel=error
+npm run --prefix ./assets deploy
+
+# Run an explicit clean beforehand
+mix do local.hex --force, \
+       clean --only $MIX_ENV, \
+       deps.get --only $MIX_ENV, \
+       compile --force, \
+       release --overwrite, \
+       phx.digest

+ 40 - 0
priv/build/cross_build.sh

@@ -0,0 +1,40 @@
+#!/bin/bash
+set -euo pipefail
+
+get_app() {
+  mix run --no-start -e "Mix.Project.config[:app] |> IO.puts" | tail -1
+}
+
+get_version() {
+  mix run --no-start -e "Mix.Project.config[:version] |> IO.puts" | tail -1
+}
+
+APP_NAME=`get_app`
+APP_VERSION=`get_version`
+OS_VERSION=${OS_VERSION?not set}
+MIX_ENV=${MIX_ENV-prod}
+
+ROOT_DIR=`pwd`
+SOURCE_DIR=$ROOT_DIR
+BUILD_DIR=$ROOT_DIR/priv/build/
+
+DOCKER_DIR=$BUILD_DIR/$OS_VERSION
+DOCKER_IMAGE_VERSION=`echo $APP_VERSION | sed "s#+#-#"`
+DOCKER_IMAGE_TAG=$APP_NAME-$OS_VERSION:$DOCKER_IMAGE_VERSION
+
+
+build_image() {
+  docker build -t $DOCKER_IMAGE_TAG $DOCKER_DIR
+}
+
+build_binary() {
+  docker run -e SOURCE_DIR=/app \
+             -e MIX_ENV=$MIX_ENV \
+             -e DOCKER_IMAGE_TAG=$DOCKER_IMAGE_TAG \
+             -v $ROOT_DIR:/app \
+             $DOCKER_IMAGE_TAG \
+             /app/priv/build/build.sh
+}
+
+build_image
+build_binary

+ 31 - 0
priv/build/debian_10/Dockerfile

@@ -0,0 +1,31 @@
+FROM debian:10.8-slim AS builder
+
+ENV TERM=xterm
+ENV DEBIAN_FRONTEND noninteractive
+
+RUN apt-get update && apt-get install -y locales git wget vim gnupg gnupg1 gnupg2
+
+## Set LOCALE to UTF8
+RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && \
+    locale-gen en_US.UTF-8 && \
+    dpkg-reconfigure locales && \
+    /usr/sbin/update-locale LANG=en_US.UTF-8
+
+ENV LC_ALL en_US.UTF-8
+
+RUN \
+  wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && \
+  dpkg -i erlang-solutions_2.0_all.deb && \
+  rm erlang-solutions_2.0_all.deb && \
+  apt-get update -y && \
+  apt-get install -y elixir
+
+RUN apt-get install -y curl build-essential && \
+    curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - && \
+    apt-get install -y nodejs
+
+WORKDIR /app
+ENV HOME /tmp/home
+
+USER 1000:1000
+CMD ["/bin/bash"]

+ 9 - 0
priv/build/get_latest_rel_dir.sh

@@ -0,0 +1,9 @@
+#!/bin/sh
+
+get_app() {
+  mix run --no-start -e "Mix.Project.config[:app] |> IO.puts" | tail -1
+}
+
+APP_NAME=`get_app`
+
+find _build/prod/rel/$APP_NAME/releases -type d -exec stat -c "%n %Y" {} \; | sort -rnk 2,2 | head -1 | cut -d ' ' -f 1 | xargs realpath

+ 3 - 0
priv/build/get_latest_tar.sh

@@ -0,0 +1,3 @@
+#!/bin/sh
+
+find _build/prod/ -name "*.tar.gz" -exec stat -c "%n %Y" {} \; | sort -rnk 2,2 | head -1 | cut -d ' ' -f 1 | xargs realpath

+ 32 - 0
priv/build/setup-git-hooks.sh

@@ -0,0 +1,32 @@
+#!/bin/sh
+# Install git hooks
+
+CHECK_FORMAT="mix format --check-formatted"
+WRITE_VERSION="git describe --always --tags --match "v*" | sed 's/^v//' | sed 's/-/+/2' > VERSION"
+
+cat <<EOF > .git/hooks/pre-commit
+#!/bin/sh
+$CHECK_FORMAT
+EOF
+
+cat <<EOF > .git/hooks/post-commit
+#!/bin/sh
+$WRITE_VERSION
+EOF
+
+cat <<EOF > .git/hooks/post-checkout
+#!/bin/sh
+$WRITE_VERSION
+EOF
+
+cat <<EOF > .git/hooks/post-merge
+#!/bin/sh
+$WRITE_VERSION
+EOF
+
+cat <<EOF > .git/hooks/post-rewrite
+#!/bin/sh
+$WRITE_VERSION
+EOF
+
+chmod +x .git/hooks/pre-commit .git/hooks/post-commit .git/hooks/post-checkout .git/hooks/post-merge .git/hooks/post-rewrite