Refactor build steps

This commit is contained in:
Anthony Mineo 2020-03-07 11:01:21 -05:00
parent d17efed959
commit 964b024b02
7 changed files with 57 additions and 21 deletions

2
.env.example Normal file
View file

@ -0,0 +1,2 @@
GO111MODULE=on
CGO_ENABLED=0

1
.envrc Normal file
View file

@ -0,0 +1 @@
dotenv

View file

@ -11,10 +11,6 @@ Parser for DarkTiger's T2 Server Stats
package main
import (
_ "github.com/amineo/t2-stat-parser"
)
func main() {
init()
initParser()
}

View file

@ -9,7 +9,7 @@ Parser for DarkTiger's T2 Server Stats
- Ability to download stat files from remote server via FTP
*/
package parser
package main
import (
"bufio"
@ -69,7 +69,7 @@ type Game struct {
uuid string `db.games:"uuid"`
}
func init() {
func initParser() {
start := time.Now()
flag.Parse()
var err error

15
app/t2-stats/start.sh Executable file
View file

@ -0,0 +1,15 @@
#!/bin/sh
echo "starting..";
echo "Checking if build exists.."
if [ -f /app/main ]
then
echo "Build found!"
/app/main
else
echo "No build found, running from source"
go run *.go
fi

View file

@ -1,19 +1,42 @@
FROM golang:1.13.6
# [ Stage 1] Builder
FROM golang:alpine AS builder
# Set necessary environmet variables needed for our image
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /app
COPY ./app/t2-stats /app
# Copy and download dependency using go mod
RUN go mod download
# # Go Packages
# RUN go get -u -v \
# # GUID Generator
# github.com/rs/xid \
# # PostgreSQL Driver
# github.com/jackc/pgx \
# github.com/jmoiron/sqlx \
# # Better Error Handling
# github.com/pkg/errors
RUN go build -o main .
# [ Stage 2]
FROM golang:alpine
LABEL maintainer="Anthony Mineo <anthonymineo@gmail.com>"
WORKDIR /app
# Go Packages
RUN go get -u -v \
# GUID Generator
github.com/rs/xid \
# PostgreSQL Driver
github.com/jackc/pgx \
github.com/jmoiron/sqlx \
# Better Error Handling
github.com/pkg/errors
COPY --from=builder /app/main /app/main
COPY ./app/t2-stats/start.sh /app/start.sh
COPY ./app/t2-stats /app
ENTRYPOINT go run main.go
ENTRYPOINT ./start.sh

View file

@ -4,7 +4,6 @@ version: "3.7"
services:
app:
command: go run /app/main.go
environment:
DATABASE_URL: "postgres://dev:dev@db:5432/t2_stats"
volumes: