I was wondering how do you deploy a FastAPI app on to Heroku as my current procfile configuration doesn't work.
web: gunicorn wsgi:app
api: uvicorn main:app --host=0.0.0.0 --port=${PORT:-5000}
Related
I have project with Laravel 9 and Vite and faced the problem when deploy app to host. I use docker, docker-compose and Gitlab CI/CD
TL;DR - manifest.json from vite must be accessible from app container, but assets build and store in other container. How can i send this file to app container?
My flow:
Push tag to Gitlab and start CI/CD
(Build stage) Build docker containers
app container with Laravel exposing php-fpm
web container with Nginx proxy requests to app and host static files
(public/build)
(Prepare stage) Clean containers from dev dependencies and upload to registry
(Deploy stage) Start docker-compose service on the host with builded containers
The problem is in manifest.json file from Vite. This is web Dockerfile:
FROM nginx:1.15.3 as base
COPY ./deployment/dockerfiles/web/default.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www/public
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
EXPOSE 80
FROM node:16.15.1-alpine as builder
WORKDIR /source
COPY ./package.json /source/
COPY ./yarn.lock /source/
RUN yarn install --frozen-lockfile
COPY ./vite.config.js /source
COPY ./resources/js /source/resources/js
COPY ./resources/css /source/resources/css
RUN yarn run build
FROM base
COPY --from=builder /source/public .
CMD ["service", "nginx", "start"]
For now, i have /public/build/ directory in web container with manifest.json and assets, but app container dont know about it - and when i start service - face the exception
Vite manifest not found at: /var/www/public/build/manifest.json
For now, i solve this problem in deploy stage - after docker-compose up just copy file from web service to app service - but this not look like production ready solution - because container in registry not ready to start without manipulation with service.
Then, question - how can i share manifest.json to app container on build stage? Or any other way?
I have a problem with deploy my docker image with my application in heroku Container Registry.
My application packed to a docker image. It mapped to work by port 8085. But also I have to provide to test my application on heroku.
My playback steps are:
1. heroku login.
heroku container login.
heroku create my-app.
docker tag my-image registry.heroku.com/my-app/web.
docker push registry.heroku.com/my-app/web.
Setting environment variables:
SPRING_DATASOURCE_URL: jdbc:oracle:thin:#IP:1521:xe
SPRING_DATASOURCE_USERNAME: apiusername
SPRING_DATASOURCE_PASSWORD: apiuserpassword
SPRING_DATASOURCE_DRIVER-CLASS-NAME: oracle.jdbc.OracleDriver
SPRING_JPA_DATABASE-PLATFORM: org.hibernate.dialect.Oracle10gDialect
SPRING_DATASOURCE_TYPE: org.apache.tomcat.jdbc.pool.DataSource
SPRING_JPA_HIBERNATE_DDL-AUTO: update
PORT: 8085
JAVA_TOOL_OPTIONS: -Xmx300m
heroku container:release web --app my-app
After this step I have an error:
Releasing images web to my-app... !
▸ No command specified for process type web
what am I doing wrong?
So my Procfile currenlty looks like:
web: gunicorn --preload --log-file - application:app
worker: celery -A celery worker --loglevel=INFO --beat
This costs 2 dynos and my worker has very low usage at the moment. Is there a way to run both gunicorn and the worker with a single dyno?
When I push an existing Docker image to Heroku, Heroku provides a $PORT environment variable. How can I pass this property to the Heroku run instance?
On localhost this would work:
docker pull swaggerapi/swagger-ui
docker run -p 80:8080 swaggerapi/swagger-ui
On Heroku I should do:
docker run -p $PORT:8080 swaggerapi/swagger-ui
Is something like this possible?
The question is quite old now, but still I will write my answer here if it can be of some help to others.
I have spring-boot App along with swagger-ui Dockerized and deployed on Heroku.
This is my application.yml looks like:
server:
port: ${PORT:8080}
forward-headers-strategy: framework
servlet:
contextPath: /my-app
springdoc:
swagger-ui:
path: '/swagger-ui.html'
Below is my DockerFile configuration.
FROM maven:3.5-jdk-8 as maven_build
WORKDIR /app
COPY pom.xml .
RUN mvn clean package -Dmaven.main.skip -Dmaven.test.skip && rm -r target
COPY src ./src
RUN mvn package spring-boot:repackage
########run stage########
FROM openjdk:8-jdk-alpine
WORKDIR /app
RUN apk add --no-cache bash
COPY --from=maven_build /app/target/springapp-1.1.1.jar ./
#run the app
# 256m was necessary for me, as I am using free version so Heroku was giving me memory quota limit exception therefore, I restricted the limit to 256m
ENV JAVA_OPTS "-Xmx256m"
ENTRYPOINT ["java","${JAVA_OPTS}", "-jar","-Dserver.port=${PORT}", "springapp-1.1.1.jar"]
The commands I used to create the heroku app:
heroku create
heroku stack:set container
The commands I used to build image and deploy:
docker build -t app-image .
heroku container:push web
heroku container:release web
Finally make sure on Heroku Dashboard the dyno information looks like this:
web java \$\{JAVA_OPTS\} -jar -Dserver.port\=\$\{PORT\} springapp-1.1.1.jar
After all these steps, I was able to access the swagger-ui via
https://testapp.herokuapp.com/my-app/swagger-ui.html
Your Docker container is required to listen to HTTP traffic in the port specified by Heroku.
Looking at the Dockerfile in the Github repo for swaggerapi/swagger-ui, it looks like it already supports the PORT environment variable: https://github.com/swagger-api/swagger-ui/blob/be72c292cae62bcaf743adc6236707962bc60bad/Dockerfile#L13
So maybe you don't really need to do anything?
It looks like this image would just work, if shipped to Heroku as a web app.
Say I'm working on a web project that runs gitlab-ci shell runner on my own ci server to build docker and deploy it to heroku, and I've gone through some docs from both gitlab and heroku like gitlab-ci: using docker build and heroku:Build and Deploy with Docker. Can I deploy the docker project without using heroku-docker plugin, which seems not so flexible to me? However I tried, the following approach build succeeded in deploying to heroku, but the app crash. Heroku logs says start script is missing in package.json, but since I'm deploying docker project, I couldn't do "start": "docker-compose up" there, could I?
#.gitlab-ci.yml
stages:
- deploy
before_script:
- npm install
- bower install
dev:
stage: deploy
script:
- docker-compose run nginx run-test
- gem install dpl
- dpl --provider=heroku --app=xixi-web-dev --api-key=$HEROKU_API_KEY
only:
- dev
# docker-compose.yml
app:
build: .
volumes:
- .:/code:ro
expose:
- "3000"
working_dir: /code
command: pm2 start app.dev.json5
nginx:
build: ./setup/nginx
restart: always
volumes:
- ./setup/nginx/sites-enabled:/etc/nginx/sites-enabled:ro
- ./dist:/var/app:ro
ports:
- "$PORT:80"
links:
- app
I don't want to use heroku docker plugin, because it seems less flexible, I can't create a app.json because I don't want to use an existing docker image for my app. Instead, I define custom Dockerfiles for app and nginx used in docker-compose.yml
Now it seems that heroku wouldn't detect my project as a docker project unless I deploy it by using heroku docker plugin, but as I mentioned above, I can't do that. Then is there any docs I'm missing on heroku or gitlab could help me out? Or do you have any idea that might be helpful? Thanks a lot!
OK, seems that heroku docker:release is required. I ended up installing heroku cli and heroku docker plugin on my CI server and use heroku docker:release --app app to release my app