Tell Aptible that you want to provision an App. Until you push code and trigger a build, Aptible uses this as a placeholder.
To create an App, use the Dashboard, or the
aptible apps:create command:
# Set or substitute $APP_HANDLE with the app name of your choice aptible apps:create "$APP_HANDLE"
Aptible will provide your App's Git Remote in return. Copy it, you'll need it later.
Going forward in this document, we'll refer to the App's handle as
$APP_HANDLE, and its Remote as
aptible db:create "$DB_HANDLE" --type postgresql
Make sure you set or substitute
$DB_HANDLE with the database name of your choice (alternatively, you could use the Dashboard to create a Database as well).
Going forward in this document, we'll refer to the Credential as
Databases are only reachable from within your Stack's internal network.
A few guidelines:
- The file needs to be called
Dockerfile, starting with a capital letter, and no extension.
- Place the
Dockerfileat the root of the repository.
- Be sure to commit them to version control.
Here is a sample Dockerfile for a Ruby on Rails App:
FROM ruby:2.4 # System prerequisites RUN apt-get update \ && apt-get -y install build-essential libpq-dev \ && rm -rf /var/lib/apt/lists/* # If you require additional OS dependencies, install them here: # RUN apt-get update \ # && apt-get -y install imagemagick nodejs \ # && rm -rf /var/lib/apt/lists/* ADD Gemfile /app/ ADD Gemfile.lock /app/ WORKDIR /app RUN bundle install ADD . /app # Collect assets. This approach is not fully production-ready, but # will help you experiment with Aptible before bothering with assets. # Review http://go.aptible.com/assets for production-ready advice. RUN set -a \ && . ./.aptible.env \ && bundle exec rake assets:precompile EXPOSE 3000 CMD ["bundle", "exec", "rails", "s", "-b", "0.0.0.0", "-p", "3000"]
See Optimizing Dockerfile caching for Bundler to better understand this Dockerfile.
Review How do I serve static assets when using Aptible? for in-depth advice on asset precompilation and serving.
Finally, your app probably expects you to run database migrations upon deploy to ensure your app code and database are in sync.
You can tell Aptible to run your migrations by adding a
.aptible.yml file in your repository.
The file should be named
.aptible.yml, and found at the root of your repository (make sure to check it in after creating it).
Here is a sample
.aptible.yml file to automate Database migrations:
before_release: - bundle exec rake db:migrate
At this point, you're almost ready to deploy.
All that is left to do is put the pieces together by configuring your App to point it to your Database, then you'll be ready to push your code to Aptible.
To add the required environment variables, use the
aptible config:set command as documented below. Make sure you set or substitute
$DATABASE_URL with their proper values.
aptible config:set --app "$APP_HANDLE" \ "DATABASE_URL=$DATABASE_URL"
Once you're done, push your code to Aptible by adding Aptible as a git remote for your app, and then using
git push to push your code:
git remote add aptible "$GIT_REMOTE" git push aptible master
Deploy logs will stream to your terminal. They'll be useful in case anything goes wrong to understand the cause of the failure.
At this point, your App is running on Aptible. What's next is expose it on the Internet!
Follow the instructions here to proceed: How do I expose my web app on the Internet?.
Updated 11 months ago