Further work on single docker container
- Add proper .dockerignore - Fix photo prefix - Print public endpoint when server starts - Discard API_LISTEN_PORT
This commit is contained in:
parent
48e2fd66a4
commit
48520a7d2d
|
@ -0,0 +1,12 @@
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.prettierrc
|
||||||
|
.vscode
|
||||||
|
photos_path
|
||||||
|
screenshots
|
||||||
|
|
||||||
|
ui/node_modules/
|
||||||
|
ui/dist/
|
||||||
|
ui/.cache/
|
||||||
|
|
||||||
|
api/photo_cache
|
|
@ -7,7 +7,7 @@ ENV GRAPHQL_ENDPOINT=${GRAPHQL_ENDPOINT}
|
||||||
RUN mkdir -p /app
|
RUN mkdir -p /app
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
COPY ui/package*.json ./
|
COPY ui/package*.json /app/
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY ui /app
|
COPY ui /app
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ COPY api /app
|
||||||
RUN go get -d -v ./...
|
RUN go get -d -v ./...
|
||||||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o photoview .
|
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o photoview .
|
||||||
|
|
||||||
# Copy built app to nginx environment
|
# Copy api and ui to production environment
|
||||||
FROM alpine:latest
|
FROM alpine:latest
|
||||||
|
|
||||||
COPY --from=ui /app/dist /ui
|
COPY --from=ui /app/dist /ui
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
MYSQL_URL=user:password@tcp(localhost)/dbname
|
MYSQL_URL=user:password@tcp(localhost)/dbname
|
||||||
|
|
||||||
API_ENDPOINT=http://localhost:4001/
|
API_ENDPOINT=http://localhost:4001/
|
||||||
API_LISTEN_PORT=4001
|
|
||||||
|
|
||||||
PUBLIC_ENDPOINT=http://localhost:1234/
|
PUBLIC_ENDPOINT=http://localhost:1234/
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
@ -64,11 +65,19 @@ func NewPhotosFromRows(rows *sql.Rows) ([]*Photo, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *PhotoURL) URL() string {
|
func (p *PhotoURL) URL() string {
|
||||||
imageUrl, err := url.Parse(os.Getenv("API_ENDPOINT"))
|
|
||||||
if err != nil {
|
publicUrl := os.Getenv("PUBLIC_ENDPOINT")
|
||||||
return path.Join("/photo", p.PhotoName)
|
if publicUrl == "" {
|
||||||
|
publicUrl = os.Getenv("API_ENDPOINT")
|
||||||
}
|
}
|
||||||
imageUrl.Path = path.Join(imageUrl.Path, "photo", p.PhotoName)
|
|
||||||
|
imageUrl, err := url.Parse(publicUrl)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Endpoint url is not properly configured, make sure the PUBLIC_ENDPOINT AND API_ENDPOINT environment variables are set correctly")
|
||||||
|
return p.PhotoName
|
||||||
|
}
|
||||||
|
|
||||||
|
imageUrl.Path = path.Join(imageUrl.Path, "api", "photo", p.PhotoName)
|
||||||
return imageUrl.String()
|
return imageUrl.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,11 +75,6 @@ func main() {
|
||||||
|
|
||||||
devMode := os.Getenv("DEVELOPMENT") == "1"
|
devMode := os.Getenv("DEVELOPMENT") == "1"
|
||||||
|
|
||||||
port := os.Getenv("API_LISTEN_PORT")
|
|
||||||
if port == "" {
|
|
||||||
port = defaultPort
|
|
||||||
}
|
|
||||||
|
|
||||||
db := database.SetupDatabase()
|
db := database.SetupDatabase()
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
|
@ -134,10 +129,15 @@ func main() {
|
||||||
endpointRouter.PathPrefix("/").Handler(spa)
|
endpointRouter.PathPrefix("/").Handler(spa)
|
||||||
|
|
||||||
if devMode {
|
if devMode {
|
||||||
log.Printf("🚀 Graphql playground ready at %s", endpointURL.String())
|
log.Printf("🚀 Graphql playground ready at %s\n", endpointURL.String())
|
||||||
} else {
|
} else {
|
||||||
log.Printf("Photoview API endpoint available at %s", endpointURL.String())
|
log.Printf("Photoview API endpoint listening at %s\n", endpointURL.String())
|
||||||
|
|
||||||
|
publicEndpoint := os.Getenv("PUBLIC_ENDPOINT")
|
||||||
|
if publicEndpoint != "" && publicEndpoint != endpointURL.String() {
|
||||||
|
log.Printf("Photoview API public endpoint ready at %s\n", publicEndpoint)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+port, rootRouter))
|
log.Fatal(http.ListenAndServe(":"+endpointURL.Port(), rootRouter))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,21 +13,26 @@ services:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
|
|
||||||
photoview:
|
photoview:
|
||||||
build: .
|
build:
|
||||||
|
context: "."
|
||||||
|
args:
|
||||||
|
- GRAPHQL_ENDPOINT=http://localhost:8000/api/graphql
|
||||||
|
|
||||||
restart: always
|
restart: always
|
||||||
ports:
|
ports:
|
||||||
- "8000:80"
|
- "8000:80"
|
||||||
depends_on:
|
depends_on:
|
||||||
- db
|
- db
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
- MYSQL_URL=photoview:photo-secret@tcp(db)/photoview
|
- MYSQL_URL=photoview:photo-secret@tcp(db)/photoview
|
||||||
- PHOTO_CACHE=/app/cache
|
- PHOTO_CACHE=/app/cache
|
||||||
# Change This: The publicly exposed url for the api
|
# Change This: The publicly exposed url for the api
|
||||||
# For example if the server is available from the domain example.com,
|
# For example if the server is available from the domain example.com,
|
||||||
# change this value to http://example.com/api
|
# change this value to http://example.com/api
|
||||||
- API_ENDPOINT=http://localhost:8080/
|
- API_ENDPOINT=http://localhost:80/
|
||||||
- PUBLIC_ENDPOINT=http://localhost:8080/
|
- PUBLIC_ENDPOINT=http://localhost:8000/
|
||||||
- API_LISTEN_PORT=80
|
|
||||||
volumes:
|
volumes:
|
||||||
# Change This: Link photo paths from the host machine
|
# Change This: Link photo paths from the host machine
|
||||||
# Change this to the directory where your photos are located on your server.
|
# Change this to the directory where your photos are located on your server.
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
node_modules/
|
|
||||||
dist/
|
|
||||||
.cache/
|
|
Loading…
Reference in New Issue