Improve build and scripts (#30)

* Use absolute path rather than relative path in scripts

* Remove src/bitBetter/.keys/cert.cert

* Build licenseGen in Docker
This way we don't have to install dotnet sdk on the host

* Build bitBetter in Docker
This way we don't have to install dotnet sdk on the host

* Change DIR in run.sh to point to the project root

* Replace echo in Dockerfiles by set -x and set -e

* Use same Dockerfile for api and identity images

* Update README.md

* Update CircleCI config
The Docker Executor can't mount volume.
https://support.circleci.com/hc/en-us/articles/360007324514
https://circleci.com/docs/2.0/executor-types/#using-machine

* Make scripts work with sh

* Remove the container used to build bitBetter
This commit is contained in:
Vinrobot 2019-07-07 18:18:27 +02:00 committed by Jeff Alyanak
parent 5d01d3c661
commit 3e44d7347b
12 changed files with 67 additions and 80 deletions

View File

@ -1,15 +1,12 @@
version: 2
jobs:
build:
docker:
- image: microsoft/dotnet:2-sdk
machine: true
steps:
- checkout
- run:
name: Print the Current Time
command: date
- setup_remote_docker
- run: { name: 'Get docker', command: 'curl -fsSL get.docker.com -o get-docker.sh && sh get-docker.sh' }
- run:
name: Generate Keys
command: ./.keys/generate-keys.sh

View File

@ -3,15 +3,18 @@
# Check for openssl
command -v openssl >/dev/null 2>&1 || { echo >&2 "openssl required but not found. Aborting."; exit 1; }
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
# Remove any existing key files
[ ! -e cert.pem ] || rm cert.pem
[ ! -e key.pem ] || rm key.pem
[ ! -e cert.cert ] || rm cert.cert
[ ! -e cert.pfx ] || rm cert.pfx
[ ! -e "$DIR/cert.pem" ] || rm "$DIR/cert.pem"
[ ! -e "$DIR/key.pem" ] || rm "$DIR/key.pem"
[ ! -e "$DIR/cert.cert" ] || rm "$DIR/cert.cert"
[ ! -e "$DIR/cert.pfx" ] || rm "$DIR/cert.pfx"
# Generate new keys
openssl req -x509 -newkey rsa:4096 -keyout .keys/key.pem -out .keys/cert.cert -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test
openssl x509 -inform DER -in .keys/cert.cert -out .keys/cert.pem
openssl pkcs12 -export -out .keys/cert.pfx -inkey .keys/key.pem -in .keys/cert.pem -passin pass:test -passout pass:test
openssl req -x509 -newkey rsa:4096 -keyout "$DIR/key.pem" -out "$DIR/cert.cert" -days 36500 -subj '/CN=www.mydom.com/O=My Company Name LTD./C=US' -outform DER -passout pass:test
openssl x509 -inform DER -in "$DIR/cert.cert" -out "$DIR/cert.pem"
openssl pkcs12 -export -out "$DIR/cert.pfx" -inkey "$DIR/key.pem" -in "$DIR/cert.pem" -passin pass:test -passout pass:test
ls

View File

@ -22,7 +22,6 @@ The following instructions are for unix-based systems (Linux, BSD, macOS), it is
Aside from docker, which you also need for Bitwarden, BitBetter requires the following:
* openssl (probably already installed on most Linux or WSL systems)
* dotnet-sdk-2.1 (install instructions can be found [here](https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-2.1.604))
## Setting up BitBetter
With your pre-requisites installed, begin the installation of BitBetter by downloading it through Github or using the git command:
@ -31,15 +30,6 @@ With your pre-requisites installed, begin the installation of BitBetter by downl
git clone https://github.com/jakeswenson/BitBetter.git
```
First, we need to add the correct version of Newtonsoft.Json to the license generator and the BitBetter docker directories.
```bash
cd BitBetter/src/licenseGen/
dotnet add package Newtonsoft.Json --version 12.0.1
cd ../bitBetter
dotnet add package Newtonsoft.Json --version 12.0.1
```
## Building BitBetter
Now that you've set up your build environment, you can **run the main build script** to generate a modified version of the `bitwarden/api` and `bitwarden/identity` docker images.

View File

@ -1,24 +1,18 @@
#!/bin/bash
#!/bin/sh
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
# If there aren't any keys, generate them first.
[ -e ./.keys/cert.cert ] || ./.keys/generate-keys.sh
[ -e "$DIR/.keys/cert.cert" ] || "$DIR/.keys/generate-keys.sh"
[ -e ./src/bitBetter/api/.keys ] || mkdir ./src/bitBetter/api/.keys
[ -e ./src/bitBetter/identity/.keys ] || mkdir ./src/bitBetter/identity/.keys
[ -e "$DIR/src/bitBetter/.keys" ] || mkdir "$DIR/src/bitBetter/.keys"
cp .keys/cert.cert ./src/bitBetter/api/.keys
cp .keys/cert.cert ./src/bitBetter/identity/.keys
cp "$DIR/.keys/cert.cert" "$DIR/src/bitBetter/.keys"
cd ./src/bitBetter
docker run --rm -v "$DIR/src/bitBetter:/bitBetter" -w=/bitBetter mcr.microsoft.com/dotnet/core/sdk:2.1 sh build.sh
dotnet restore
dotnet publish
docker build --build-arg BITWARDEN_TAG=bitwarden/api -t bitbetter/api "$DIR/src/bitBetter" # --squash
docker build --build-arg BITWARDEN_TAG=bitwarden/identity -t bitbetter/identity "$DIR/src/bitBetter" # --squash
cp -r bin/ api/
cp -r bin/ identity/
cd ./api
docker build --pull . -t bitbetter/api # --squash
cd ../identity
docker build --pull . -t bitbetter/identity # --squash

Binary file not shown.

11
src/bitBetter/Dockerfile Normal file
View File

@ -0,0 +1,11 @@
ARG BITWARDEN_TAG
FROM ${BITWARDEN_TAG}
COPY bin/Debug/netcoreapp2.0/publish/* /bitBetter/
COPY ./.keys/cert.cert /newLicensing.cer
RUN set -e; set -x; \
dotnet /bitBetter/bitBetter.dll && \
mv /app/Core.dll /app/Core.orig.dll && \
mv /app/modified.dll /app/Core.dll && \
rm -rf /bitBetter && rm -rf /newLicensing.cer

View File

@ -1,12 +0,0 @@
FROM bitwarden/api
COPY bin/Debug/netcoreapp2.0/publish/* /bitBetter/
COPY ./.keys/cert.cert /newLicensing.cer
RUN dotnet /bitBetter/bitBetter.dll && \
echo "modified dll" && \
mv /app/Core.dll /app/Core.orig.dll && \
mv /app/modified.dll /app/Core.dll && \
echo "replaced dll" && \
rm -rf /bitBetter && rm -rf /newLicensing.cer && \
echo "cleaned up"

8
src/bitBetter/build.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
set -e
set -x
dotnet add package Newtonsoft.Json --version 12.0.1
dotnet restore
dotnet publish

View File

@ -1,12 +0,0 @@
FROM bitwarden/identity
COPY bin/Debug/netcoreapp2.0/publish/* /bitBetter/
COPY ./.keys/cert.cert /newLicensing.cer
RUN dotnet /bitBetter/bitBetter.dll && \
echo "modified dll" && \
mv /app/Core.dll /app/Core.orig.dll && \
mv /app/modified.dll /app/Core.dll && \
echo "replaced dll" && \
rm -rf /bitBetter && rm -rf /newLicensing.cer && \
echo "cleaned up"

View File

@ -1,5 +1,17 @@
FROM mcr.microsoft.com/dotnet/core/sdk:2.1 as build
WORKDIR /licenseGen
COPY . /licenseGen
RUN set -e; set -x; \
dotnet add package Newtonsoft.Json --version 12.0.1 \
&& dotnet restore \
&& dotnet publish
FROM bitbetter/api
COPY bin/Debug/netcoreapp2.0/publish/* /app/
COPY --from=build /licenseGen/bin/Debug/netcoreapp2.0/publish/* /app/
ENTRYPOINT [ "dotnet", "/app/licenseGen.dll", "--core", "/app/Core.dll", "--cert", "/cert.pfx" ]

View File

@ -1,11 +1,6 @@
#!/bin/bash
#!/bin/sh
script_dir=`cd $(dirname $0); pwd`
cd $script_dir
dotnet restore
dotnet publish
docker build . -t bitbetter/licensegen # --squash
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
docker build -t bitbetter/licensegen "$DIR" # --squash

View File

@ -1,18 +1,19 @@
#!/bin/bash
#!/bin/sh
script_dir=`cd $(dirname $0); pwd`
DIR=`dirname "$0"`
DIR=`exec 2>/dev/null;(cd -- "$DIR") && cd -- "$DIR"|| cd "$DIR"; unset PWD; /usr/bin/pwd || /bin/pwd || pwd`
# Grab the absolute path to the default pfx location
cert_path=`cd ./.keys; ls -d -1 $PWD/cert.pfx`
cert_path="$DIR/.keys/cert.pfx"
if [ "$#" -lt "1" ]; then
echo "USAGE: $0 <ABSOLUTE PATH TO CERT.PFX> [License Gen args...]"
exit 1
elif [ "$#" -ge "2" ]; then
# If a cert path is provided manually, override the default
cert_path=$1
cert_path="$1"
shift
fi
docker run -it -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@"
docker run -it --rm -v "$cert_path:/cert.pfx" bitbetter/licensegen "$@"