Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add production deployment documentation (#271)

Madison Swain-Bowdenadafb42db58d
diff --git a/DEPLOY.md b/DEPLOY.md
new file mode 100644
index 000000000..b84069768
--- /dev/null
+++ b/DEPLOY.md
@@ -0,0 +1,40 @@
+# Deployment
+
+This document describes the steps necessary for deploying the catalog on our AWS EC2 instance.
+For convenience (and access frequency), instructions for deploying an update are provided first.
+If you wish to deploy a new instance, see [Deploying a fresh instance](#deploying-a-fresh-instance).
+
+**Note**: All steps assume that the environment variable `IS_PROD` is set to `true` in the bash session being used for deployment.
+If it is not `export`ed for the session, `IS_PROD=true` will need to be prepended to all `just` commands (e.g. `IS_PROD=true just build`)
+
+## Deploying an update to DAG files
+
+1. `git pull` _(Yes, that's it! Airflow will take a few moments to populate the changes.)_
+
+## Deploying an update to the Docker image or non-DAG code
+
+1. Verify that any new Airflow Variables, Airflow Connections, or environment variables have been added or updated.
+2. Run `just deploy` within the repository's folder.
+
+## Deploying a fresh instance
+
+1. Clone the repository onto the target machine.
+2. Run `just dotenv` to create a new `.env` file from the template.
+3. Generate a secure password for the `airflow` account on the Airflow Metastore DB, and update the account using `ALTER USER airflow WITH PASSWORD '<generated-password>';` _(Note: this process will be changed in [gh-260](https://github.com/WordPress/openverse-catalog/issues/260))_
+4. Create an `AIRFLOW__CORE__FERNET_KEY` using the instructions described in the `.env` file
+5. Change the following variables in the `.env` file:
+ - **(Required)**
+ - `AIRFLOW__CORE__SQL_ALCHEMY_CONN` (using the password created above)
+ - `AIRFLOW__CORE__HIDE_SENSITIVE_VAR_CONN_FIELDS`
+ - `AIRFLOW_CONN_AWS_DEFAULT`
+ - `AIRFLOW_CONN_POSTGRES_OPENLEDGER_UPSTREAM`
+ - `AIRFLOW_CONN_POSTGRES_OPENLEDGER_TESTING`
+ - `AWS_ACCESS_KEY`
+ - `AWS_SECRET_KEY`
+ - **(Recommended)**
+ - `AIRFLOW_PORT`
+ - `LOADER_FILE_AGE`
+ - Any API key variables
+6. Run `just build`, verify the image built correctly
+7. Run `just up`, verify that the Airflow container has started successfully
+8. Run `just airflow "users create -r Admin -u <username> -f <first-name> -l <last-name> -p <password> --email <email>"` with desired information to create an Administrator account for the Airflow UI
diff --git a/README.md b/README.md
index 0a118f0ae..ac1bef734 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,8 @@ loaded into a database to be indexed for searching in the Openverse API. These r
different environment than the PySpark portion of the project, and so have their
own dependency requirements.
+For instructions geared specifically towards production deployments, see [DEPLOY.md](DEPLOY.md).
+
[api_scripts]: openverse_catalog/dags/providers/provider_api_scripts
### Requirements
diff --git a/deploy_in_prod.sh b/deploy_in_prod.sh
deleted file mode 100755
index bb9f700b0..000000000
--- a/deploy_in_prod.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/bash
-#
-# This script shows git status, asks for confirmation, then runs the steps
-# necessary to deploy the Apache Airflow webserver container (and dependencies)
-# to production.
-
-set -o errexit
-set -o errtrace
-set -o nounset
-
-trap '_es=${?};
- printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
- printf " exited with a status of ${_es}\n";
- exit ${_es}' ERR
-
-deploy_with_docker_compose() {
- docker-compose -f docker-compose.yml build webserver
- docker-compose -f docker-compose.yml up -d webserver
-}
-
-git status
-
-echo "Are you sure you want to deploy a production Airflow container?"
-read -r -p "Type 'YES' in all caps to confirm > " response
-if [[ "$response" == "YES" && -f .env ]]; then
- echo "Typed YES, and .env exists. Deploying..."
- deploy_with_docker_compose
-else
- echo "Canceling"
-fi
diff --git a/docker-compose.override.yml b/docker-compose.override.yml
index fa4d20782..71cb240df 100644
--- a/docker-compose.override.yml
+++ b/docker-compose.override.yml
@@ -56,10 +56,7 @@ services:
- REQUIREMENTS_FILE=requirements_dev.txt
# This command ensures an admin account is created on startup
command: init
- # Volume override to include *all* of openverse_catalog, not just the DAGs folder
- # Note, this overrides the whole block, so existing volumes must be duplicated
volumes:
- - airflow:/var/workflow_output
- ./openverse_catalog:/usr/local/airflow/openverse_catalog
volumes:
diff --git a/docker/airflow/Dockerfile b/docker/airflow/Dockerfile
index 6a434ffa1..0c04d8aea 100644
--- a/docker/airflow/Dockerfile
+++ b/docker/airflow/Dockerfile
@@ -32,7 +32,9 @@ RUN apt-get update && apt-get -yqq upgrade && apt-get -yqq install \
libffi-dev \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*
-RUN useradd -m -d ${AIRFLOW_HOME} airflow
+RUN useradd -m -d ${AIRFLOW_HOME} airflow && \
+ mkdir -p ${OUTPUT_DIR} && \
+ chown airflow:airflow ${OUTPUT_DIR}
USER airflow
WORKDIR ${AIRFLOW_HOME}
diff --git a/env.template b/env.template
index 2ecdb9740..0e5f65ac3 100644
--- a/env.template
+++ b/env.template
@@ -65,9 +65,6 @@ AIRFLOW_PORT=9090
LOADER_FILE_AGE=1
# Contact email for any APIs
-# This is where intermediate TSVs and other files will be written
-# In production, this should be a permanent (non-temp) location
-OUTPUT_DIR=/tmp/
# AWS/S3 configuration - does not need to be changed for development
AWS_ACCESS_KEY=test_key
AWS_SECRET_KEY=test_secret