Skip to content
Snippets Groups Projects
Commit d7402d35 authored by nimrod's avatar nimrod
Browse files

Most of it, if not all of it.

parent 037022dc
No related branches found
No related tags found
No related merge requests found
*
!awslogs.conf
!config
!deduce-aws-region
!entrypoint
~*
*~
*.sw[op]
*.py[cod]
.DS_Store
__pycache__/
.vagrant/
vendor/
Thumbs.db
*.retry
.svn/
.sass-cache/
*.log
*.out
*.so
node_modules/
.npm/
nbproject/
*.ipynb
.idea/
*.egg-info/
*.[ao]
.classpath
.cache/
bower_components/
*.class
*.[ewj]ar
secring.*
.*.kate-swp
.swp.*
.directory
.Trash-*
build/
_build/
dist/
.tox/
*.pdf
*.exe
*.dll
*.gz
*.tgz
*.tar
*.rar
*.zip
*.pid
*.lock
*.env
.bundle/
!Pipfile.lock
# vim:ff=unix ts=2 sw=2 ai expandtab
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-added-large-files
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: detect-private-key
- id: trailing-whitespace
- repo: https://github.com/adrienverge/yamllint
rev: v1.17.0
hooks:
- id: yamllint
- repo: https://github.com/amperser/proselint
rev: 0.10.1
hooks:
- id: proselint
types: [plain-text]
exclude: LICENSE
- repo: https://www.shore.co.il/git/docker-pre-commit
rev: v0.3.0
hooks:
- id: hadolint
- repo: https://github.com/ambv/black
rev: 19.3b0
hooks:
- id: black
args:
- |
--line-length=79
- repo: https://gitlab.com/pycqa/flake8
rev: 3.7.8
hooks:
- id: flake8
args:
- |-
--max-line-length=79
additional_dependencies:
- flake8-bugbear
FROM python:3.7-alpine3.10
# hadolint ignore=DL3013
RUN pip install --no-cache-dir --progress-bar=off \
awscli-cwlogs \
template \
&& \
install -d -o nobody -g root -m 755 /var/awslogs/etc/
COPY --chown=root:root config /etc/aws/
COPY --chown=root:root entrypoint /usr/local/bin/
COPY --chown=root:root awslogs.conf /var/awslogs/etc/awslogs.conf.j2
COPY --chown=root:root deduce-aws-region /usr/local/bin/
USER nobody
ENV AWS_CONFIG_FILE="/etc/aws/config" \
LOG_GROUP_NAME="" \
LOG_STREAM_NAME="" \
LOG_FILE=""
ENTRYPOINT ["entrypoint"]
CMD ["aws", "logs", "push", "--config-file", "/tmp/config"]
HEALTHCHECK CMD pgrep python || exit 1
MIT License
Copyright (c) 2019 Adar Nimrod
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# AWS ClougWatch Agent
Send files to CloudWatch logs.
## Usage
Run with the directory of the log file mounted inside the container and
specifying the `LOG_GROUP_NAME`, `LOG_STREAM_NAME` and `LOG_FILE` environment
variables. Also, the usual [AWS CLI environment
variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)
can also be specified. Lastly, the AWS region is deduced on startup by accessing
the [instance
metadata](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html#instancedata-data-retrieval),
unless the `AWS_DEFAULT_REGION` enviroment variable is specified. By default the
container uses the `nobody` user, but you may need to specify a different user
in case the log file is not readable but that user. For [file rotation
detection](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html#agent-faq),
don't mount just the file but the whole directory inside the container.
## Example usage
```
docker run -d -v '/var/log:/var/log:ro' -e 'LOG_GROUP_NAME=/var/log/' -e 'LOG_STREAM_NAME={instance_id}' -e 'LOG_FILE=/var/log/ecs/ecs-agent.log.*' adarnimrod/cw-logs
```
## License
This software is licensed under the MIT license (see `LICENSE.txt`).
## Author Information
Nimrod Adar, [contact me](mailto:nimrod@shore.co.il) or visit my [website](
https://www.shore.co.il/). Patches are welcome via [`git send-email`](
http://git-scm.com/book/en/v2/Git-Commands-Email). The repository is located
at: <https://www.shore.co.il/git/>.
[general]
state_file = /tmp/push-state
[LOG_FILE]
file = {{ LOG_FILE }}
log_group_name = {{ LOG_GROUP_NAME }}
log_stream_name = {{ LOG_STREAM_NAME }}
config 0 → 100644
[plugins]
cwlogs = cwlogs
#!/usr/bin/env python3
from urllib.request import urlopen
import json
if __name__ == "__main__":
response = urlopen(
"http://169.254.169.254/latest/dynamic/instance-identity/document"
)
print(json.loads(response.read().decode("utf-8"))["region"])
#!/bin/sh
set -eux
template /var/awslogs/etc/awslogs.conf.j2 > /tmp/config
if [ -z "${AWS_DEFAULT_REGION:-}" ]
then
AWS_DEFAULT_REGION="$(deduce-aws-region)"
export AWS_DEFAULT_REGION
fi
eval exec "$@"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment