Skip to content

Commit

Permalink
docker compose, dockerfiles, Quasar upgrade, initialize and clean up …
Browse files Browse the repository at this point in the history
…DB after deploy
  • Loading branch information
valasek committed Oct 9, 2019
1 parent c1c5e60 commit a641129
Show file tree
Hide file tree
Showing 18 changed files with 516 additions and 55 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,3 @@ server/data/exported/*.csv
server/data/uploaded/*.csv
timesheet-backup.zip
logs/*.log

# private seed data
*_dataarch.csv
*-dataarch.yaml
timesheet-prod.yaml
timesheet-prod.dataarch.yaml
3 changes: 2 additions & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"dev": "cross-env QENV=development quasar dev",
"build-da": "cross-env QENV=production-dataarch quasar build",
"build-dev": "cross-env QENV=production-dev quasar build",
"build-cloud": "cross-env QENV=production-cloud quasar build",
"build": "cross-env QENV=production quasar build",
"lint": "eslint --ext .js,.vue src",
Expand All @@ -32,7 +33,7 @@
},
"devDependencies": {
"@quasar/app": "^1.1.4",
"@quasar/quasar-app-extension-icon-genie": "^1.0.2",
"@quasar/quasar-app-extension-icon-genie": "^1.1.0",
"@quasar/quasar-app-extension-qenv": "^1.0.0-beta.2",
"@quasar/quasar-app-extension-qmarkdown": "^1.0.0-beta.21",
"@quasar/quasar-app-extension-testing-quality": "^1.0.0-beta.8",
Expand Down
4 changes: 2 additions & 2 deletions client/quasar.extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"@quasar/qenv": {
"common_root_object": "none",
"add_qenv_to_gitignore": true
"add_qenv_to_gitignore": false
},
"@quasar/icon-genie": {
"minify_dev": "pngquant",
Expand All @@ -30,4 +30,4 @@
}
}
}
}
}
8 changes: 4 additions & 4 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1189,10 +1189,10 @@
resolved "https://registry.yarnpkg.com/@quasar/fastclick/-/fastclick-1.1.4.tgz#21ed3e9a4387dcb43022a08af4ef08a5f1abf159"
integrity sha512-i9wbyV4iT+v4KhtHJynUFhH5LiEPvAEgSnwMqPN4hf/8uRe82nDl5qP5agrp2el1h0HzyBpbvHaW7NB0BPrtvA==

"@quasar/quasar-app-extension-icon-genie@^1.0.2":
version "1.0.2"
resolved "https://registry.yarnpkg.com/@quasar/quasar-app-extension-icon-genie/-/quasar-app-extension-icon-genie-1.0.2.tgz#0dc6c2543d5236829176a7c5fba2c911a415250b"
integrity sha512-hx+/0gJZxgniLzs0P4v4DC1g+hCJQxbH6/Tc9uWbSUtwwOJy6b56N6fVacIQgqp7x2ThaTzCH2ylRzqXS+epSw==
"@quasar/quasar-app-extension-icon-genie@^1.1.0":
version "1.1.0"
resolved "https://registry.yarnpkg.com/@quasar/quasar-app-extension-icon-genie/-/quasar-app-extension-icon-genie-1.1.0.tgz#0260687c3e9ae694f774a17b47bc9234eb13c3ab"
integrity sha512-hGZp1TiaafMEzQgq+dRNuNJXTn2qkqHeK7B4/U4GqALEsSCi+3SAy6sMUKjiV1vS0twEfTROuGqoyNqhpmXt2w==
dependencies:
elementtree "^0.1.7"
execa "^2.0.4"
Expand Down
24 changes: 24 additions & 0 deletions docker-compose-cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright © 2018-2019 Stanislav Valasek <[email protected]>
version: "3.3"

services:
server:
build:
context: .
dockerfile: ./dockerfiles/cloud/Dockerfile
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
ports:
- "3000:3000"
depends_on:
- "db"
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: timesheet
POSTGRES_USER: timesheet
POSTGRES_DB: timesheet
ports:
- "5432:5432"
# sudo docker run --name pg-docker -e POSTGRES_USER=timesheet -e POSTGRES_PASSWORD=timesheet -e POSTGRES_DB=timesheet -d -p 5432:5432 postgres
24 changes: 24 additions & 0 deletions docker-compose-dataarch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright © 2018-2019 Stanislav Valasek <[email protected]>
version: "3.3"

services:
server:
build:
context: .
dockerfile: ./dockerfiles/dataarch/Dockerfile
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
ports:
- "3000:3000"
depends_on:
- "db"
db:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: timesheet
POSTGRES_USER: timesheet
POSTGRES_DB: timesheet
ports:
- "5432:5432"
# sudo docker run --name pg-docker -e POSTGRES_USER=timesheet -e POSTGRES_PASSWORD=timesheet -e POSTGRES_DB=timesheet -d -p 5432:5432 postgres
8 changes: 6 additions & 2 deletions docker-compose.yml → docker-compose-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

services:
server:
build: .
build:
context: .
dockerfile: ./dockerfiles/dev/Dockerfile
sysctls:
- net.ipv6.conf.all.disable_ipv6=1
ports:
- "3000:3000"
depends_on:
Expand All @@ -16,5 +20,5 @@
POSTGRES_USER: timesheet
POSTGRES_DB: timesheet
ports:
- "5432:5432"
- "5432:5432"
# sudo docker run --name pg-docker -e POSTGRES_USER=timesheet -e POSTGRES_PASSWORD=timesheet -e POSTGRES_DB=timesheet -d -p 5432:5432 postgres
8 changes: 6 additions & 2 deletions Dockerfile → dockerfiles/cloud/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ ADD ./server/logs/ /logs
RUN chmod -R ug+rwx /logs
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
COPY ./server/timesheet-cloud.yaml /timesheet.yaml
# COPY ./server/timesheet-dataarch.yaml /timesheet.yaml
# COPY ./server/timesheet-dev.yaml /timesheet.yaml
RUN chmod +x /docker-entrypoint.sh

# Import the code from the context.
Expand Down Expand Up @@ -66,12 +68,14 @@ COPY ./client/ ./
# install project dependencies
RUN yarn install
RUN yarn global add @quasar/cli
RUN quasar upgrade -i
# RUN quasar upgrade -i

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY ./client ./

# build app for production with minification
# build app for production with minification use build-cloud or build-da
# RUN yarn run build-dev
# RUN yarn run build-da
RUN yarn run build-cloud
# RUN ls -la ./
# RUN ls -la ./dist
Expand Down
122 changes: 122 additions & 0 deletions dockerfiles/dataarch/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Copyright © 2018-2019 Stanislav Valasek <[email protected]>

# Accept the Go version for the image to be set as a build argument.
# Default to Go 1.13
ARG GO_VERSION=1.13

###########################################
# First stage: build the backend executable.
# FROM golang:${GO_VERSION}-alpine AS builder
FROM golang:alpine AS backend

# Create the user and group files that will be used in the running container to
# run the process as an unprivileged user.
RUN mkdir /user && \
echo 'nobody:x:65534:65534:nobody:/:' > /user/passwd && \
echo 'nobody:x:65534:' > /user/group

# Install the Certificate-Authority certificates for the app to be able to make
# calls to HTTPS endpoints.
# Git is required for fetching the dependencies.
RUN apk add --no-cache ca-certificates git

# Set the working directory outside $GOPATH to enable the support for modules.
WORKDIR /src

# Fetch dependencies first; they are less susceptible to change on every build
# and will therefore be cached for speeding up the next build
COPY ./server/go.mod ./go.mod
RUN go mod download
ADD ./server/data/ /data
RUN chmod -R ug+rw /data
ADD ./server/documentation/ /documentation
ADD ./server/documentation/ /documentation/statics
RUN chmod -R ug+rw /documentation
ADD ./server/logs/ /logs
RUN chmod -R ug+rwx /logs
COPY ./docker-entrypoint.sh /docker-entrypoint.sh
# COPY ./server/timesheet-dev.yaml /timesheet.yaml
COPY ./server/timesheet-dataarch.yaml /timesheet.yaml
# COPY ./server/timesheet-cloud.yaml /timesheet.yaml
RUN chmod +x /docker-entrypoint.sh

# Import the code from the context.
COPY ./server/ ./

# Build the executable to `/app`. Mark the build as statically linked.
# RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" CGO_ENABLED=0 \
# -installsuffix 'static' \
# -o /app .
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build \
-ldflags "-X github.com/valasek/timesheet/server/version.Version=1.4.4" \
-installsuffix 'static' -o /timesheet.bin .
# RUN ls -la .

##############################################
# Second stage: build the frontend executable.
FROM node:lts-alpine AS frontend
# fix due to optipng-bin in icon-factory - https://github.com/imagemin/optipng-bin/issues/84
RUN apk --no-cache add pkgconfig autoconf automake libtool nasm build-base zlib-dev

# make the 'client' folder the current working directory
WORKDIR /client

# copy both 'package.json' and 'package-lock.json' (if available)
COPY ./client/package*.json ./
COPY ./client/ ./

# install project dependencies
RUN yarn install
RUN yarn global add @quasar/cli
RUN quasar upgrade -i

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY ./client ./

# build app for production with minification use build-cloud or build-da
# RUN yarn run build-dev
RUN yarn run build-da
# RUN yarn run build-cloud
# RUN ls -la ./
# RUN ls -la ./dist
# RUN chmod -R ug+rw ./dist

# EXPOSE 8080
# CMD [ "http-server", "dist" ]

#####################################
# Final stage: the running container.
# FROM scratch AS final
FROM alpine AS final

# Import the user and group files from the first stage.
COPY --from=backend /user/group /user/passwd /etc/

# Import the Certificate-Authority certificates for enabling HTTPS.
COPY --from=backend /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Import the compiled executable from the first stage.
COPY --from=backend /timesheet.bin /timesheet.bin
# Copy data folder
COPY --from=backend /data /data
# Copy documentation folder
COPY --from=backend /documentation /documentation
# Copy log folder
COPY --from=backend /logs /logs
# Copy compiled frontend files
COPY --from=frontend /client/dist/spa /client/dist

# Declare the port on which the webbackend will be exposed.
# As we're going to run the executable as an unprivileged user, we can't bind
# to ports below 1024.
# Expose is NOT supported by Heroku
# EXPOSE 3000

# Perform any further action as an unprivileged user.
# USER nobody:nobody

COPY --from=backend /docker-entrypoint.sh /docker-entrypoint.sh
COPY --from=backend /timesheet.yaml /timesheet.yaml
# Run the compiled binary.
ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["/docker-entrypoint.sh --debug=5"]
Loading

0 comments on commit a641129

Please sign in to comment.