From c216051de84c23a0bc0d1ea42f63a47af9d4d3a7 Mon Sep 17 00:00:00 2001 From: Ivan Subotic <400790+subotic@users.noreply.github.com> Date: Thu, 5 Nov 2020 18:40:20 +0100 Subject: [PATCH] DSP-995 Building of Docker images on release (#11) --- .dockerignore | 31 +++++++++++++++++++++++++++++++ .editorconfig | 2 +- .github/workflows/main.yml | 23 +++++++++++++++++++++++ Dockerfile | 38 ++++++++++++++++++++++++++++++++++++++ Makefile | 22 ++++++++++++++++++++++ README.md | 3 ++- angular.json | 4 ++-- package.json | 3 ++- vars.mk | 12 ++++++++++++ 9 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 .dockerignore create mode 100644 .github/workflows/main.yml create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 vars.mk diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b93f4f0 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,31 @@ +# compiled output +/dist +/tmp + +# dependencies +/node_modules +/bower_components + +# IDEs and editors +/.idea +.project +.classpath +*.launch +.settings/ + +# misc +/.sass-cache +/connect.lock +/coverage/* +/libpeerconnection.log +npm-debug.log +testem.log +/typings + +# e2e +/e2e/*.js +/e2e/*.map + +#System Files +.DS_Store +Thumbs.db diff --git a/.editorconfig b/.editorconfig index 9b73521..6e87a00 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,7 +4,7 @@ root = true [*] charset = utf-8 indent_style = space -indent_size = 4 +indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..ff0c102 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,23 @@ +name: CI + +on: + push: + release: + types: [published] + +jobs: + test: + name: Build + runs-on: ubuntu-latest + steps: + - name: Checkout Source + uses: actions/checkout@v1 + with: + fetch-depth: 50 + - name: Build Docker Image + run: make build-app-image + - name: Publish Docker Image (on release only) + if: github.event_name == 'release' && startsWith(github.ref, 'refs/tags') + run: | + echo ${{ secrets.DOCKER_HUB_TOKEN }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin + make publish-app-image diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..8cc6f98 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +### STAGE 1: Build ### + +# We label our stage as 'builder' +FROM node:12-stretch as builder + +# The qq is for silent output in the console +# You are welcome to modify this part as it +RUN apt-get update -qq && apt-get install -y build-essential libpq-dev + +# Sets the path where the app is going to be installed +ENV NODE_ROOT /usr/app/ + +# Creates the directory and all the parents (if they don’t exist) +RUN mkdir -p $NODE_ROOT + +# Sets the /usr/app as the active directory +WORKDIR $NODE_ROOT + +# Copies all the content +COPY . . + +# Install all the packages +RUN npm install -g @angular/cli +RUN npm install + +## Build the angular app in production mode and store the artifacts in dist folder +## should be: $(npm bin)/ng build --prod --env=prod --build-optimizer +RUN npm run build-prod + +### STAGE 2: Setup ### + +FROM dhlabbasel/nginx-server:v1.0.1 + +LABEL maintainer="400790+subotic@users.noreply.github.com" + +RUN rm -rf /public/* + +COPY --from=builder /usr/app/dist/limcweb /public diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ad96134 --- /dev/null +++ b/Makefile @@ -0,0 +1,22 @@ +# Determine this makefile's path. +# Be sure to place this BEFORE `include` directives, if any. +# THIS_FILE := $(lastword $(MAKEFILE_LIST)) +THIS_FILE := $(abspath $(lastword $(MAKEFILE_LIST))) +CURRENT_DIR := $(shell dirname $(realpath $(firstword $(MAKEFILE_LIST)))) + +include vars.mk + +.PHONY: build-app-image +build-app-image: ## build and publish APP image locally + docker build -t $(APP_IMAGE) . + docker tag $(APP_IMAGE) $(APP_REPO):latest + +.PHONY: publish-app-image +publish-app-image: build-app-image ## publish APP Docker image to Docker-Hub + docker push $(APP_REPO) + +.PHONY: help +help: ## this help + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) | sort + +.DEFAULT_GOAL := help diff --git a/README.md b/README.md index 7256abc..503329a 100644 --- a/README.md +++ b/README.md @@ -32,5 +32,6 @@ You may find our live website at [weblimc.org](http://www.weblimc.org). ## Imprint This web application has been developed from 2014 to 2019 by Andreas Aeschlimann, University of Basel. +It is maintained by Rita Gautschi, Data and Service Center for the Humanities, University of Basel. -Contact: a.aeschlimann@unibas.ch \ No newline at end of file +Contact: rita.gautschi@dasch.swiss diff --git a/angular.json b/angular.json index 3dc482e..a1f9873 100644 --- a/angular.json +++ b/angular.json @@ -11,7 +11,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist", + "outputPath": "dist/limcweb", "index": "src/index.html", "main": "src/main.ts", "tsConfig": "src/tsconfig.json", @@ -130,4 +130,4 @@ "prefix": "app" } } -} \ No newline at end of file +} diff --git a/package.json b/package.json index b01c9e3..96dfad3 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ "start": "ng serve", "test": "ng test", "pree2e": "webdriver-manager update --standalone false --gecko false", - "e2e": "protractor" + "e2e": "protractor", + "build-prod": "ng build --prod --build-optimizer" }, "private": true, "dependencies": { diff --git a/vars.mk b/vars.mk new file mode 100644 index 0000000..a2ac56b --- /dev/null +++ b/vars.mk @@ -0,0 +1,12 @@ +APP_REPO := daschswiss/080e-limc-app + +ifeq ($(BUILD_TAG),) + BUILD_TAG := $(shell git describe --tag --dirty --abbrev=7) +endif +ifeq ($(BUILD_TAG),) + BUILD_TAG := $(shell git rev-parse --verify HEAD) +endif + +ifeq ($(APP_IMAGE),) + APP_IMAGE := $(APP_REPO):$(BUILD_TAG) +endif