Skip to content

Commit

Permalink
apache2 is now in docker. using env variables to set bucket. moved te…
Browse files Browse the repository at this point in the history
…mplates to template directory
  • Loading branch information
abessiari committed Nov 24, 2021
1 parent 9fef918 commit 13c4a07
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 29 deletions.
9 changes: 8 additions & 1 deletion docker/Dockerfile.proxy
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ RUN a2dismod mpm_event mpm_worker \
EXPOSE 80

COPY ./entrypoint-proxy.sh /entrypoint.sh

# used by logrotate-to-s3.sh
ENV S3_PATH=logrotate
ENV S3_BUCKET=bucket

COPY ./apache2 /etc/logrotate.d/apache2
COPY ./logrotate-to-s3.sh /opt/bin/logrotate-to-s3.sh
RUN chmod +x /entrypoint.sh /opt/bin/logrotate-to-s3.sh

RUN chmod +x /entrypoint.sh /opt/bin/logrotate-to-s3.sh && chmod 400 /etc/logrotate.d/apache2
ENTRYPOINT [ "/entrypoint.sh" ]
CMD ["tail", "-f", "/dev/null" ]
20 changes: 20 additions & 0 deletions docker/apache2
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/var/log/apache2/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 640 root adm
postrotate
UPLOAD_CMD="s3cmd -c /opt/credentials/s3cfg --mime-type=text/plain put" NAME_PREFIX="" /opt/bin/logrotate-to-s3.sh "$@"
if invoke-rc.d apache2 status > /dev/null 2>&1; then \
invoke-rc.d apache2 reload > /dev/null 2>&1; \
fi;
endscript
prerotate
if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
run-parts /etc/logrotate.d/httpd-prerotate; \
fi; \
endscript
}
23 changes: 12 additions & 11 deletions docker/logrotate-to-s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#

usage() {
echo "Usage: logrotate-to-s3 your-bucket-name [ file ... ]" >&2
echo "Usage: logrotate-to-s3 [ file ... ]" >&2
echo "To see help text, yun can run 'logrotate-to-s3 -h' for usage." >&2
exit 1
}
Expand All @@ -17,7 +17,7 @@ logrotate-to-s3:
Usage:
logrotate-to-s3 your-bucket-name [ file ... ]
logrotate-to-s3 [ file ... ]
Environment variables:
Expand All @@ -29,13 +29,13 @@ Environment variables:
Examples:
$ logrotate-to-s3 mybucket /var/log/nginx/access.log
$ logrotate-to-s3 /var/log/nginx/access.log
=> s3://mybucket/logrotate/your-hostname/2016/01/access.log.20160102-030405.gz
$ S3_PATH=archive/staging NAME_PREFIX=nginx logrotate-to-s3 mybucket /var/log/nginx/access.log
$ S3_PATH=archive/staging NAME_PREFIX=nginx logrotate-to-s3 /var/log/nginx/access.log
=> s3://mybucket/archive/staging/your-hostname/2016/01/nginx-access.log.20160102-030405.gz
$ S3_PATH=app-log PREFIX="dt=$(date "+%Y-%m-%d")" logrotate-to-s3 mybucket /var/log/nginx/access.log
$ S3_PATH=app-log PREFIX="dt=$(date "+%Y-%m-%d")" logrotate-to-s3 /var/log/nginx/access.log
=> s3://mybucket/app-log/dt=2016-01-02/nginx-access.log.20160102-030405.gz
Configuration logroate:
Expand All @@ -55,30 +55,30 @@ Configuration logroate:
"/var/log/nginx/access.log" {
sharedscripts
postrotate
logrotate-to-s3 mybucket "$@"
logrotate-to-s3 "$@"
endscript
}
# bad - because of wildcarded patterns
/var/log/nginx/*.log {
lastaction
logrotate-to-s3 mybucket "$@"
logrotate-to-s3 "$@"
endscript
}
# bad - because space character is placed in the back of the pattern
/var/log/nginx/access.log {
sharedscripts
postrotate
logrotate-to-s3 mybucket "$@"
logrotate-to-s3 "$@"
endscript
}
# okish - it works, but "shardscripts" and "lastaction" are not recommended.
/var/log/nginx/access.log{
sharedscripts
postrotate
logrotate-to-s3 mybucket "$@"
logrotate-to-s3 "$@"
endscript
}
EOF
Expand All @@ -95,6 +95,7 @@ readonly default_suffix="$(date "+%Y%m%d-%H%M%S")"

# Default Configurations
readonly s3_path=${S3_PATH:-logrotate}
readonly s3_bucket=${S3_BUCKET:-bucket}
readonly name_prefix=${NAME_PREFIX:+$NAME_PREFIX-}
readonly upload_cmd=${UPLOAD_CMD:-aws s3 cp}

Expand Down Expand Up @@ -154,8 +155,8 @@ main() {

[[ $# -ge 1 ]] || usage

local bucket=$1
local -a paths=("${@:2}")
local bucket=$s3_bucket
local -a paths=("${@:1}")

for path in "${paths[@]}"; do
upload "$bucket" "$path"
Expand Down
4 changes: 2 additions & 2 deletions provision/build_image.yaml → provision/build_images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
version: '{{ branch }}'
force: yes

- name: build image
- name: build amigo image
shell: "docker build -f {{ repo_dir }}/docker/Dockerfile -t 'amigo:{{ tag }}' {{ repo_dir }}"

- name: build image
- name: build proxy image
shell: "docker build -f {{ repo_dir }}/docker/Dockerfile.proxy -t 'go-apache:{{ tag }}' {{ repo_dir }}/docker"
25 changes: 14 additions & 11 deletions provision/stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,20 @@
- not CREATE_INDEX
- not index_result.stat.exists

- name: Create proxy-configs directory
file:
path: '{{ stage_dir }}/proxy-configs'
state: directory

- name: install docker-compose.yaml and http configs
- name: install docker-compose.yaml and http configs ...
template:
src: '{{ item.file }}'
dest: '{{ stage_dir }}/{{ item.dir }}'
src: 'templates/{{ item.file }}'
dest: '{{ stage_dir }}{{ item.dir }}/{{ item.file }}'
with_items:
- { file: 'amigo.yaml', dir: '' }
- { file: '001-inline-amigo.conf', dir: '' }
- { file: 'apache2.ports.conf', dir: '' }
- { file: 'docker-compose.yaml', dir: '' }
- { file: 'httpd-vhosts-amigo.conf', dir: '' }
- { file: 'httpd-vhosts-golr.conf', dir: '' }
- { file: 'apache2', dir: '' }
- { file: 's3cfg', dir: '' }
- { file: 'amigo.yaml', dir: '/' }
- { file: '001-inline-amigo.conf', dir: '/' }
- { file: 'apache2.ports.conf', dir: '/' }
- { file: 'docker-compose.yaml', dir: '/' }
- { file: 'httpd-vhosts-amigo.conf', dir: '/proxy-configs' }
- { file: 'httpd-vhosts-golr.conf', dir: '/proxy-configs' }
- { file: 's3cfg', dir: '/proxy-configs' }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ services:
restart: unless-stopped
environment:
- USE_S3={{ USE_S3 }}
- S3_PATH={{ S3_PATH }}
- S3_BUCKET={{ S3_BUCKET }}
volumes:
- {{ stage_dir }}/httpd-vhosts-amigo.conf:/etc/apache2/sites-enabled/httpd-vhosts-amigo.conf
- {{ stage_dir }}/httpd-vhosts-golr.conf:/etc/apache2/sites-enabled/httpd-vhosts-golr.conf
- {{ stage_dir }}/proxy-configs/s3cfg:/opt/credentials/s3cfg
- {{ stage_dir }}/proxy-configs/httpd-vhosts-amigo.conf:/etc/apache2/sites-enabled/httpd-vhosts-amigo.conf
- {{ stage_dir }}/proxy-configs/httpd-vhosts-golr.conf:/etc/apache2/sites-enabled/httpd-vhosts-golr.conf
- {{ stage_dir }}/apache_proxy_logs:/var/log/apache2
- {{ stage_dir }}/apache2:/etc/logrotate.d/apache2
- {{ stage_dir }}/s3cfg:/opt/credentials/s3cfg
ports:
- "80:80"
depends_on:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 13c4a07

Please sign in to comment.