Add DOCKERFILE

This commit is contained in:
Marco Realacci 2022-12-12 19:05:23 +01:00
parent e86526761c
commit a53799d441
3 changed files with 72 additions and 23 deletions

2
.vscode/launch.json vendored
View file

@ -10,7 +10,7 @@
"type": "go", "type": "go",
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"buildFlags": "", "buildFlags": "-tags webui",
"program": "./cmd/webapi", "program": "./cmd/webapi",
"args": [ "args": [
"--db-filename", "/home/marco/wasa/wasadata/wasaphoto.db", "--data-path", "/home/marco/wasa/wasadata/data" "--db-filename", "/home/marco/wasa/wasadata/wasaphoto.db", "--data-path", "/home/marco/wasa/wasadata/data"

71
Dockerfile Normal file
View file

@ -0,0 +1,71 @@
# This file is used by Docker "build" or "buildah" to create a container image for this Go project
# The build is done using "multi-stage" approach, where a temporary container ("builder") is used to build the Go
# executable, and the final image is from scratch (empty container) for both security and performance reasons.
# DO NOT MODIFY UNLESS IT'S STRICTLY NECESSARY
ARG DOCKER_PREFIX
FROM ${DOCKER_PREFIX}node:lts AS uibuilder
COPY webui webui
WORKDIR webui
RUN npm config set update-notifier false && npm install && npm run build-embed
ARG DOCKER_PREFIX
FROM ${DOCKER_PREFIX}enrico204/golang:1.19.4-6 AS builder
# Disable Go proxy and public checksum for private repositories (Go 1.13+)
ENV GOPRIVATE github.com/notherealmarco/WASAPhoto
### Copy Go code
COPY . .
COPY --from=uibuilder webui webui
### Set some build variables
ARG APP_VERSION
ARG BUILD_DATE
ARG REPO_HASH
RUN go generate -mod=vendor ./...
### Build executables, strip debug symbols and compress with UPX
WORKDIR /src/cmd/
#RUN mkdir /app/
RUN /bin/bash -euo pipefail -c "for ex in \$(ls); do pushd \$ex; CGO_ENABLED=1 go build -tags webui,openapi -mod=vendor -ldflags \"-extldflags \\\"-static\\\" -X main.AppVersion=${APP_VERSION} -X main.BuildDate=${BUILD_DATE}\" -a -installsuffix cgo -o /app/\$ex .; popd; done"
RUN cd /app/ && strip * && upx -9 *
### Create final container from scratch
FROM scratch
### Inform Docker about which port is used
EXPOSE 3000 4000
### Populate scratch with CA certificates and Timezone infos from the builder image
ENV ZONEINFO /zoneinfo.zip
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /zoneinfo.zip /
COPY --from=builder /etc/passwd /etc/passwd
### Copy the build executable from the builder image
WORKDIR /app/
COPY --from=builder /app/* ./
### Set some build variables
ARG APP_VERSION
ARG BUILD_DATE
ARG PROJECT_NAME
ARG GROUP_NAME
### Downgrade to user level (from root)
USER appuser
### Executable command
CMD ["/app/webapi", "--db-filename", "/data/wasaphoto.db", "--data-path", "/data/data"]
### OpenContainers tags
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="${GROUP_NAME} - ${PROJECT_NAME}" \
org.opencontainers.image.authors="SapienzaApps <sapienzaapps@gmail.com>" \
org.opencontainers.image.source="https://github.com/notherealmarco/${GROUP_NAME}/${PROJECT_NAME}" \
org.opencontainers.image.revision="${REPO_HASH}" \
org.opencontainers.image.vendor="SapienzaApps" \
org.opencontainers.image.version="${APP_VERSION}"

View file

@ -4,28 +4,6 @@ import getCurrentSession from './services/authentication';
import { updateToken } from './services/axios'; import { updateToken } from './services/axios';
</script> </script>
<script>
export default {
data() {
return {
currentSession: "",
}
},
created() {
if (!this.getCurrentSession()) {
this.$router.push({ path: "/login" });
} else {
updateToken()
}
},
computed: {
linkTo() {
return "/profile/" + this.getCurrentSession();
}
}
}
</script>
<template> <template>
<!--<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow"> <!--<header class="navbar navbar-dark sticky-top bg-dark flex-md-nowrap p-0 shadow">