R
Railway

✋|help

Need help with deployment

DDev4019/18/2023
Subject: Seeking Guidance on Loading Environment Variables in Railway for My Go API Deployment Hi everyone, I hope you're all doing well. I'm currently working on deploying my Go API on Railway, and I've run into a bit of a challenge. Specifically, I need to figure out how to load environment variables from a .env file in Railway. Locally, I've been able to load these variables successfully. Here's a snippet of my .env file for reference:
# Firebase project ID
FIREBASE_PROJECT_ID=jobs-scraxxxxx-xxxx

# Path to your Firebase service account credentials JSON file
FIREBASE_CREDENTIALS_FILE=cred.json

# Port for your application (optional, you can use a default port if not specified)
PORT=8080
# Firebase project ID
FIREBASE_PROJECT_ID=jobs-scraxxxxx-xxxx

# Path to your Firebase service account credentials JSON file
FIREBASE_CREDENTIALS_FILE=cred.json

# Port for your application (optional, you can use a default port if not specified)
PORT=8080
In my main.go file, I'm loading these environment variables like this:
projectID := os.Getenv("FIREBASE_PROJECT_ID")
credentialsFile := os.Getenv("FIREBASE_CREDENTIALS_FILE")

// Initialize Firestore client using environment variables.
opt := option.WithCredentialsFile(credentialsFile)
firestoreClient, err := firestore.NewClient(context.Background(), projectID, opt)
if err != nil {
log.Fatalf("Error initializing Firestore client: %v", err)
}

r.GET("/syncFirestore", func(c *gin.Context) {
handlers.SyncWithFireBase(c, firestoreClient)
})

r.GET("/getJobsFromFirestore", func(c *gin.Context) {
handlers.GetJobsFromFirestore(c, firestoreClient)
})
projectID := os.Getenv("FIREBASE_PROJECT_ID")
credentialsFile := os.Getenv("FIREBASE_CREDENTIALS_FILE")

// Initialize Firestore client using environment variables.
opt := option.WithCredentialsFile(credentialsFile)
firestoreClient, err := firestore.NewClient(context.Background(), projectID, opt)
if err != nil {
log.Fatalf("Error initializing Firestore client: %v", err)
}

r.GET("/syncFirestore", func(c *gin.Context) {
handlers.SyncWithFireBase(c, firestoreClient)
})

r.GET("/getJobsFromFirestore", func(c *gin.Context) {
handlers.GetJobsFromFirestore(c, firestoreClient)
})
Now, the challenge I'm facing is how to load the cred.json file in Railway, as it primarily supports key-value pairs for environment variables. You can find my GitHub repository with the code here: Jobs-Scraper on GitHub I would greatly appreciate any guidance or suggestions on how to tackle this issue and successfully deploy my Go API on Railway. Thank you in advance for your assistance! Project ID: 455cfb5c-e03f-4d7c-81b7-1e2a12858525 Best regards, Mabud
No description
DDev4019/18/2023
Project ID : sweltering-air Project ID: 455cfb5c-e03f-4d7c-81b7-1e2a12858525
BBrody9/18/2023
id recommend storing that credentials file on a volume https://docs.railway.app/reference/volumes but you can deploy this template https://railway.app/template/Nan7Bs it will come with a volume, then upload that json credentials file to it, unmount the volume from the template service and then mount it to your go service

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
bun: command not foundHello, I'm trying to migrate my project to bun to make TS easier, and I'm when deploying, the logs Metrics on Number of Web RequestsI just deployed a web API and would like to keep track of the number of requests made to the API. DoIs there a timeout on my api functions when deploying a nextjs app?I coudnt find anything about this on google or the docs, Thanks for helpingI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moI have problems with the database when I do a deploy.I have a mongo DB database that is connected to a node js, to connect to mongo I use the url that moError comunicate with internal servicecsI'm trying to make a post on a route that is in an internal service on railway = api-ecompleto.railwUnchanged repo fails to deploy on env var change.I had this exact setup running last night, and this morning when I changed an environment variable iIs it possible to host Unity project?I have a unity game development project which runs C# Since I already use railway for my other projCan't see organizations reposTitle.Please my images are not displaying after deploying on railway. I am new in web development.Please I am new to web development and first time deploying to railway. I have django drf backend wiISO 27001Hi this might be a dumb question but does Railway have the ISO 27001 certification or is that irreledeploying react with viteI've deployed a react app with vite, exposing network ip but I can't access it - says Application faOpenSSL error when using Bun + PrismaGetting an error when using Bun and prisma together. Prisma requires node to work, so start command Server isnt workingThe server suddenly stopped working. Could anyone explain what is going on?...How to deploy a project with multiple dockerfiles?Have project that has one `Dockerfile` for the backend service and another one `Dockerfile.celery` fWildcard DNS let user custom there domainI would like to know how to let's my users custom domain with CNAME to my domain DNS my DOMAIN CNA