Skip to content

Instantly share code, notes, and snippets.

@yosshy
Last active December 14, 2019 12:51
Show Gist options
  • Save yosshy/c46dc1aff3a81996c216b01924e791be to your computer and use it in GitHub Desktop.
Save yosshy/c46dc1aff3a81996c216b01924e791be to your computer and use it in GitHub Desktop.
Script to generate docker-compose.yml for building AWX + Gitea environment
#!/bin/bash
USER=admin
PASSWORD=password
SYSTEM_USER=sysuser
SYSTEM_PASSWORD=nomoresecret
SECRET_KEY=secrete
FQDN="awx.example.com"
AWX_HTTPS_PORT=443
GITEA_HTTPS_PORT=8443
GITEA_SSH_PORT=10022
CERT_TTL=1024
CERT_DIR=./cert
NGINX_CONF_DIR=.
## create a certificate
mkdir -p ${CERT_DIR}
if [ ! -f ${CERT_DIR}/cert.key -o ! -f ${CERT_DIR}/cert.pem ]; then
openssl req -x509 -sha256 -newkey rsa:2048 -keyout ${CERT_DIR}/cert.key -out ${CERT_DIR}/cert.pem -days ${CERT_TTL} -nodes -subj "/CN=${FQDN}"
fi
## create nginx.conf file
/bin/cat << EOF > ${NGINX_CONF_DIR}/nginx.conf
server {
listen ${AWX_HTTPS_PORT} ssl;
server_name ${FQDN};
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate ssl/cert.pem;
ssl_certificate_key ssl/cert.key;
location / {
proxy_pass http://awx_web:8052;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-HTTPS 'True';
}
}
server {
listen ${GITEA_HTTPS_PORT} ssl;
server_name ${FQDN};
ssl on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_certificate ssl/cert.pem;
ssl_certificate_key ssl/cert.key;
location / {
proxy_pass http://gitea:3000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-HTTPS 'True';
}
}
EOF
## create docker-compose.yml file
/bin/cat << EOF > docker-compose.yml
version: '2'
services:
postgres:
image: postgres:9.6
volumes:
- pgdata:/var/lib/postgresql/data
environment:
GOSU_VERSION: "1.11"
LANG: "en_US.utf8"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/9.6/bin"
PGDATA: "/var/lib/postgresql/data/pgdata"
PG_MAJOR: "9.6"
PG_VERSION: "9.6.11-1.pgdg90+1"
POSTGRES_DB: "awx"
POSTGRES_PASSWORD: "${SYSTEM_PASSWORD}"
POSTGRES_USER: "${SYSTEM_USER}"
memcached:
image: memcached:alpine
environment:
MEMCACHED_VERSION: "1.5.12"
MEMCACHED_SHA1: "f67096ba64b0c47668bcad5b680010c4f8987d4c"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
rabbitmq:
image: ansible/awx_rabbitmq:3.7.4
volumes:
- /var/lib/rabbitmq
environment:
HOME: "/var/lib/rabbitmq"
PATH: "/opt/rabbitmq/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
RABBITMQ_DEFAULT_PASS: "${SYSTEM_PASSWORD}"
RABBITMQ_DEFAULT_USER: "${SYSTEM_USER}"
RABBITMQ_DEFAULT_VHOST: "awx"
RABBITMQ_ERLANG_COOKIE: "cookiemonster"
RABBITMQ_GITHUB_TAG: "v3.7.4"
RABBITMQ_GPG_KEY: "0A9AF2115F4687BD29803A206B73A36E6026DFCA"
RABBITMQ_HOME: "/opt/rabbitmq"
RABBITMQ_LOGS: "-"
RABBITMQ_SASL_LOGS: "-"
RABBITMQ_VERSION: "3.7.4"
awx_task:
hostname: awx
image: ansible/awx_task:2.1.2
volumes:
- /var/lib/nginx
environment:
AWX_ADMIN_PASSWORD: "${PASSWORD}"
AWX_ADMIN_USER: "${USER}"
DATABASE_HOST: "postgres"
DATABASE_NAME: "awx"
DATABASE_PASSWORD: "${SYSTEM_PASSWORD}"
DATABASE_PORT: "5432"
DATABASE_USER: "${SYSTEM_USER}"
MEMCACHED_HOST: "memcached"
MEMCACHED_PORT: "11211"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
RABBITMQ_HOST: "rabbitmq"
RABBITMQ_PASSWORD: "${SYSTEM_PASSWORD}"
RABBITMQ_PORT: "5672"
RABBITMQ_USER: "${SYSTEM_USER}"
RABBITMQ_VHOST: "awx"
SECRET_KEY: "${SECRET_KEY}"
depends_on:
- memcached
- postgres
- rabbitmq
links:
- awx_web
- memcached
- postgres
- rabbitmq
- gitea
awx_web:
hostname: awxweb
image: ansible/awx_web:2.1.2
volumes:
- /var/lib/nginx
command: "/bin/sh -c /usr/bin/launch_awx.sh"
environment:
AWX_ADMIN_PASSWORD: "${PASSWORD}"
AWX_ADMIN_USER: "${USER}"
DATABASE_HOST: "postgres"
DATABASE_NAME: "awx"
DATABASE_PASSWORD: "${SYSTEM_PASSWORD}"
DATABASE_PORT: "5432"
DATABASE_USER: "${SYSTEM_USER}"
MEMCACHED_HOST: "memcached"
MEMCACHED_PORT: "11211"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
RABBITMQ_HOST: "rabbitmq"
RABBITMQ_PASSWORD: "${SYSTEM_PASSWORD}"
RABBITMQ_PORT: "5672"
RABBITMQ_USER: "${SYSTEM_USER}"
RABBITMQ_VHOST: "awx"
SECRET_KEY: "${SECRET_KEY}"
depends_on:
- memcached
- postgres
- rabbitmq
links:
- memcached
- postgres
- rabbitmq
- gitea
postgres2:
image: postgres:9.6
volumes:
- pgdata2:/var/lib/postgresql/data
environment:
GOSU_VERSION: "1.11"
LANG: "en_US.utf8"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/postgresql/9.6/bin"
PGDATA: "/var/lib/postgresql/data/pgdata"
PG_MAJOR: "9.6"
PG_VERSION: "9.6.11-1.pgdg90+1"
POSTGRES_DB: "gitea"
POSTGRES_PASSWORD: "${SYSTEM_PASSWORD}"
POSTGRES_USER: "${SYSTEM_USER}"
gitea:
image: gitea/gitea:latest
volumes:
- gitea:/data:rw
environment:
APP_NAME: "Gitea"
DB_HOST: "postgres2"
DB_NAME: "gitea"
DB_PASSWD: "${SYSTEM_PASSWORD}"
DB_TYPE: "postgres"
DB_USER: "${SYSTEM_USER}"
DISABLE_REGISTRATION: "false"
DISABLE_SSH: "false"
GITEA_CUSTOM: "/data/gitea"
HTTP_PORT: "3000"
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ROOT_URL: "https://${FQDN}:${GITEA_HTTPS_PORT}"
RUN_MODE: "dev"
SSH_DOMAIN: "gitea"
SSH_PORT: "${GITEA_SSH_PORT}"
TZ: "Japan"
USER_GID: "1000"
USER: "git"
USER_UID: "1000"
depends_on:
- postgres2
links:
- postgres2
ports:
- "${GITEA_SSH_PORT}:${GITEA_SSH_PORT}"
nginx:
image: nginx:stable-alpine
volumes:
- ${NGINX_CONF_DIR}/nginx.conf:/etc/nginx/conf.d/default.conf
- ${CERT_DIR}:/etc/nginx/ssl
ports:
- ${AWX_HTTPS_PORT}:${AWX_HTTPS_PORT}
- ${GITEA_HTTPS_PORT}:${GITEA_HTTPS_PORT}
links:
- awx_web
- gitea
restart: always
volumes:
pgdata:
driver: local
pgdata2:
driver: local
gitea:
driver: local
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment