Skip to content
Snippets Groups Projects
Commit 060be8d8 authored by Torgrim's avatar Torgrim
Browse files

Updated Docker files for CI/CD pipeline

parent 51f988b4
No related branches found
No related tags found
No related merge requests found
......@@ -88,6 +88,6 @@ ehthumbs.db
Thumbs.db
# Personal ignore patterns
**/firebasecredentials.json
**/firebaseCredentials.json
**/.secrets
.env
\ No newline at end of file
......@@ -88,7 +88,7 @@ ehthumbs.db
Thumbs.db
# Personal ignore patterns
**/firebasecredentials.json
**/firebaseCredentials.json
**/.secrets
.env
......
PORT=8080
TOKEN=your_api_token #For Testing
TOKEN=your_api_token
FIREBASE_CREDENTIALS_FILE=path_to_Firebase_credentials_file
\ No newline at end of file
# syntax=docker/dockerfile:1.2
FROM golang:1.22 AS builder
LABEL authors="Torgrim Thorsen"
# Set destination for COPY
WORKDIR /app
# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code.
COPY ../ ./
......
# syntax=docker/dockerfile:1.2
FROM golang:1.22 AS builder
LABEL authors="Torgrim Thorsen"
# Set destination for COPY
WORKDIR /app
# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
# Copy the source code.
COPY ../ ./
......@@ -26,12 +26,5 @@ WORKDIR /root/
# Copy the pre-built binary file from the previous stage.
COPY --from=builder /app/main .
# Optional:
# To bind to a TCP port, runtime parameters must be supplied to the docker command.
# But we can document in the Dockerfile what ports
# the application is going to listen on by default.
# https://docs.docker.com/reference/dockerfile/#expose
EXPOSE 8080
# Run
CMD ["./main"]
\ No newline at end of file
......@@ -4,9 +4,9 @@ import (
"context"
firebase "firebase.google.com/go"
"firebase.google.com/go/auth"
"globeboard/internal/utils/constants"
"google.golang.org/api/option"
"log"
"os"
)
var (
......@@ -16,10 +16,10 @@ var (
func GetFireBaseAuthClient() (*auth.Client, error) {
// Using the credential file
sa := option.WithCredentialsFile(constants.FirebaseCredentialPath)
sa := option.WithCredentialsFile(os.Getenv("FIREBASE_CREDENTIALS_FILE"))
app, err := firebase.NewApp(ctx, nil, sa)
if err != nil {
log.Println("Credentials not found: " + constants.FirebaseCredentialPath)
log.Println("Credentials not found: " + os.Getenv("FIREBASE_CREDENTIALS_FILE"))
log.Println("Error on getting the application")
return nil, err
}
......@@ -28,7 +28,7 @@ func GetFireBaseAuthClient() (*auth.Client, error) {
client, err := app.Auth(ctx)
if err != nil {
// Logging the error
log.Println("Credentials file: '" + constants.FirebaseCredentialPath + "' lead to an error.")
log.Println("Credentials file: '" + os.Getenv("FIREBASE_CREDENTIALS_FILE") + "' lead to an error.")
return nil, err
}
......
......@@ -4,7 +4,6 @@ import (
"globeboard/internal/handlers"
"globeboard/internal/handlers/endpoint/dashboard"
"globeboard/internal/handlers/endpoint/util"
"globeboard/internal/utils/constants"
"globeboard/internal/utils/constants/Endpoints"
"globeboard/internal/utils/constants/Paths"
"log"
......@@ -23,7 +22,7 @@ func fileExists(filename string) bool {
}
func main() {
if !fileExists(constants.FirebaseCredentialPath) {
if !fileExists(os.Getenv("FIREBASE_CREDENTIALS_FILE")) {
log.Fatal("Firebase Credentials file is not mounted")
return
}
......
......@@ -7,7 +7,6 @@ import (
firebase "firebase.google.com/go"
"fmt"
authenticate "globeboard/auth"
"globeboard/internal/utils/constants"
"globeboard/internal/utils/constants/Firestore"
"globeboard/internal/utils/structs"
"google.golang.org/api/iterator"
......@@ -16,6 +15,7 @@ import (
"google.golang.org/grpc/status"
"log"
"net/http"
"os"
)
const (
......@@ -32,10 +32,10 @@ var (
func getFirestoreClient() (*firestore.Client, error) {
// Using the credential file
sa := option.WithCredentialsFile(constants.FirebaseCredentialPath)
sa := option.WithCredentialsFile(os.Getenv("FIREBASE_CREDENTIALS_FILE"))
app, err := firebase.NewApp(ctx, nil, sa)
if err != nil {
log.Println("Credentials not found: " + constants.FirebaseCredentialPath)
log.Println("Credentials not found: " + os.Getenv("FIREBASE_CREDENTIALS_FILE"))
log.Println("Error on getting the application")
return nil, err
}
......@@ -44,7 +44,7 @@ func getFirestoreClient() (*firestore.Client, error) {
client, err := app.Firestore(ctx)
if err != nil {
// Logging the error
log.Println("Credentials file: '" + constants.FirebaseCredentialPath + "' lead to an error.")
log.Println("Credentials file: '" + os.Getenv("FIREBASE_CREDENTIALS_FILE") + "' lead to an error.")
return nil, err
}
......
......@@ -2,28 +2,38 @@ version: "3.8"
services:
globeboard-test:
image: go-globeboard-test:latest
image: go-globeboard-test
build:
context: .
dockerfile: Dockerfile-test
restart: no
environment:
- TOKEN=${TOKEN}
TOKEN: ${TOKEN}
FIREBASE_CREDENTIALS_FILE: /run/secrets/firebase_credentials
secrets:
- firebase_credentials
volumes:
- ./.secrets:/root/.secrets:ro
- ./web:/root/web:ro
globeboard:
image: go-globeboard:latest
image: go-globeboard
build:
context: .
dockerfile: Dockerfile
ports:
- '${PORT}:${PORT}'
restart: unless-stopped
environment:
- PORT=${PORT}
- TOKEN=${TOKEN}
PORT: ${PORT}
FIREBASE_CREDENTIALS_FILE: /run/secrets/firebase_credentials
secrets:
- firebase_credentials
volumes:
- ./.secrets:/root/.secrets:ro
- ./web:/root/web:ro
depends_on:
globeboard-test:
condition: service_completed_successfully
\ No newline at end of file
condition: service_completed_successfully
secrets:
firebase_credentials:
file: ${FIREBASE_CREDENTIALS_FILE}
\ No newline at end of file
......@@ -3,9 +3,8 @@ package constants
// APIVersion represents the version of the API.
const (
APIVersion = "v1"
FirebaseCredentialPath = "./.secrets/firebaseCredentials.json"
ApiKeyLength = 20
DocIdLength = 24
IdLength = 16
APIVersion = "v1"
ApiKeyLength = 20
DocIdLength = 24
IdLength = 16
)
stages:
- test
test_globeboard:
stage: test
image: docker:19.03.12
services:
- docker:19.03.12-dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
script:
- apk add --no-cache docker-compose
- docker-compose -f Go/docker-compose.yml up --build globeboard-test
only:
- main
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment