I have problems trying to deploy a graphql API to Azure web apps (I don't know if it's the right place but here's my case)
My expectation
I want to deploy a graphql API using a docker-compose file with azure-container-registry. I use docker for local development and everything is correct. In the docker-compose file I define my local enviroment variables, and in my node.js API I reference this variables using process.env.{variable_name}
My problem
In production, I got a blank page (with no visible error log) when I was trying to access my currently deployed app link (For example https://myapp.azurewebsites.net/graphql)
Here's the stack of my graphql API: Apollo Server, Nodejs, Docker compose (I used apollo-server-express)
What I tried
I used Azure pipelines to deploy the front-end repository of my application and configured a GitHub action too. So I decided to use the same logic with my backend repository.
I already deployed my mongodb using Atlas.
I put my docker-compose-prod.yml variables between ${ } symbols because I guess this is necessary for the azure pipelines to detect where I'm going to put my variables
This is how it looks like.
# Docker
# Build and push an image to Azure Container Registry
# https://learn.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
- main
resources:
- repo: self
variables:
# Container registry service connection established during pipeline creation
dockerRegistryServiceConnection: <.....>
imageRepository: 'myimagereposity'
containerRegistry: 'mycontainerregistry.azurecr.io'
dockerfilePath: '$(Build.SourcesDirectory)/Dockerfile.dev'
tag: '$(Build.BuildId)'
dockerComposeFile: '$(Build.SourcesDirectory)/docker-compose-prod.yml'
projectName: $(Build.Repository.Name)
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build and push stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: 'Suscripcion developer 1(id-subs)'
azureContainerRegistry: '{"loginServer":"mycontainerregistry.azurecr.io", "id" : "/subscriptions/id-subs/resourceGroups/proyecto-final/providers/Microsoft.ContainerRegistry/registries/mycontainername"}'
dockerComposeFile: '**/docker-compose-prod.yml'
dockerComposeFileArgs: |
DATABASE_URL=mongodb+srv://mydb-user:$(dbpassword)@cluster0.defvz.mongodb.net/$(dbname)?retryWrites=true&w=majority
AWS_ACCESS_ID=$(AWS_ACCESS_ID)
AWS_SECRET_KEY=$(AWS_SECRET_KEY)
AWS_REGION=$(AWS_REGION)
S3_BUCKET_NAME=$(S3_BUCKET_NAME)
GOOGLE_APPLICATION_CREDENTIALS=$(GOOGLE_APPLICATION_CREDENTIALS)
action: 'Build services'
This is my Dockerfile
FROM node:12-alpine
EXPOSE 8080
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install --silent
COPY . .
CMD [ "npm", "run", "debug" ]
This is my docker-compose-prod.yml
version: '3.7'
services:
api:
container_name: 'saaga-api'
restart: 'always'
build:
context: .
dockerfile: 'Dockerfile.prod'
volumes:
# - /usr/src/app/node_modules
- '.:/usr/src/app'
environment:
NODE_ENV: production
ORIGIN: 'https://myapp.azurewebsites.net'
PORT: 8080
DATABASE_URL: ${DATABASE_URL}
AWS_ACCESS_ID: ${AWS_ACCESS_ID}
AWS_SECRET_KEY: ${AWS_SECRET_KEY}
AWS_REGION: ${AWS_REGION}
S3_BUCKET_NAME: ${S3_BUCKET_NAME}
GOOGLE_APPLICATION_CREDENTIALS: ${GOOGLE_APPLICATION_CREDENTIALS}
ports:
- 8080:8080
- 9229:9229
links:
- db
db:
container_name: 'mongodb'
image: 'mongo'
ports:
- 27017:27017
Someone knows what I'm missing or what I'm doing badly? The app works well for the local environment, the problem is only in production.
Copyright License:
Author:「Roberto」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/64944349/how-can-i-deploy-a-graphql-api-with-docker-compose-in-azure