Skip to content

Commit

Permalink
Refactor resources
Browse files Browse the repository at this point in the history
  • Loading branch information
thehedhly committed Jan 19, 2024
1 parent 6d92474 commit bdb1075
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 158 deletions.
Binary file modified .github/workflows/.DS_Store
Binary file not shown.
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

name: ci
on:
push:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 'Print docker version information'
run: |
docker --version
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 'Login to Docker Hub'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 'Build and push'
uses: docker/build-push-action@v5
with:
push: true
tags: thehedhly/ansible:latest
context: .
file: Dockerfile
41 changes: 0 additions & 41 deletions .github/workflows/docker.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

name: Lint Code Base
on:
push:
branches-ignore: [main]
pull_request:
branches: [main]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 'Yamllint'
uses: karancode/yamllint-github-action@master
with:
yamllint_file_or_dir: .
yamllint_strict: true
yamllint_comment: false
41 changes: 0 additions & 41 deletions .github/workflows/release.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .hadolint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---

ignored:
- DL3008
- DL3006 #see https://github.com/hadolint/hadolint/issues/339

Check warning on line 5 in .hadolint.yaml

View workflow job for this annotation

GitHub Actions / lint

5:12 [comments] too few spaces before comment

Check warning on line 5 in .hadolint.yaml

View workflow job for this annotation

GitHub Actions / lint

5:13 [comments] missing starting space in comment
9 changes: 9 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---

extends: default

rules:
line-length: disable
truthy:
allowed-values: ['true', 'false']
check-keys: false
100 changes: 69 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,31 +1,69 @@
FROM ubuntu:20.04
LABEL author="Hamza Hedhly"
LABEL version="Ubuntu 20.04 (Focal Fossa)"
LABEL documentation="https://github.com/senjoux"
# Supported Ansible releases:
# - 4.0 (default)
# - 3.0
# - 2.10
# see releases https://docs.ansible.com/ansible/devel/roadmap/ansible_roadmap_index.html
ENV ANSIBLE_VERSION=4.0.0
# if none provided an "ansible" user will be created
ENV ANSIBLE_USER=ansible
# Python3-pip version
ENV PYTHON3_PIP_VERSION=20.0.2-5ubuntu1.5

RUN apt-get update --no-install-recommends -y \
# prepare user
&& adduser $ANSIBLE_USER \
&& echo "$ANSIBLE_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
# install Ansible
&& apt-get install --no-install-recommends python3-pip=$PYTHON3_PIP_VERSION -y \
&& rm -rf /var/lib/apt/lists/*\
&& python3.8 -m pip install --no-cache-dir ansible==$ANSIBLE_VERSION \
# other
&& echo "export PS1='[\u@\h:\w] $ '" >> /home/$ANSIBLE_USER/.bashrc \
# self
&& ansible --version \
&& python3.8 -m pip list

ENTRYPOINT ["/bin/bash","-c"]
CMD ["su $ANSIBLE_USER"]
# Before overriding BASE_IMAGE and PYCMD, please consult:
# - https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-core-support-matrix
# and also maybe (in case want to install ansible community):
# - https://docs.ansible.com/ansible/latest/reference_appendices/release_and_maintenance.html#ansible-community-changelogs
#
ARG BASE_IMAGE="python:3.11.7-slim"
ARG PYCMD="/usr/local/bin/python3.11"
ARG SYS_ZONEINFO="Europe/Berlin"
ARG ANSIBLE_HOME="/usr/share/ansible"
ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS="-v"
ARG ANSIBLE_GALAXY_CLI_ROLE_OPTS=""
ARG ANSIBLE_INSTALL_REFS="ansible-core==2.16.0"
# ARG ANSIBLE_INSTALL_REFS="ansible-core"
# ARG ANSIBLE_INSTALL_REFS="ansible==9"
# ARG ANSIBLE_INSTALL_REFS="ansible"
ARG ANSIBLE_USER="thehedhly"

# Base build stage
FROM $BASE_IMAGE as base
USER root
ARG BASE_IMAGE
ARG PYCMD
ARG ANSIBLE_INSTALL_REFS

RUN "unlink /etc/localtime \
&& ln -s /usr/share/zoneinfo/$SYS_ZONEINFO /etc/localtime \
&& $PYCMD -m ensurepip \
&& $PYCMD -m pip install --no-cache-dir $ANSIBLE_INSTALL_REFS"
USER guest

# Galaxy build stage
FROM base as galaxy
ARG ANSIBLE_HOME
ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS
ARG ANSIBLE_GALAXY_CLI_ROLE_OPTS
WORKDIR /
COPY requirements.yml .
RUN ansible-galaxy role install $ANSIBLE_GALAXY_CLI_ROLE_OPTS -r requirements.yml --roles-path "$ANSIBLE_HOME/roles"\
&& ANSIBLE_GALAXY_DISABLE_GPG_VERIFY=1 ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path "$ANSIBLE_HOME/collections"

# Final build stage
FROM base as final
LABEL org.opencontainers.image.created="date and time on which the image was built (string, date-time as defined by RFC 3339)"
LABEL org.opencontainers.image.authors="https://github.com/thehedhly"
LABEL org.opencontainers.image.url="dockerhub url"
LABEL org.opencontainers.image.source="github repository"
LABEL org.opencontainers.image.version="version of the packaged software"
ARG ANSIBLE_HOME
ARG ANSIBLE_USER
ENV ANSIBLE_CONFIG "/home/$ANSIBLE_USER/.ansible.cfg"
# ENV ANSIBLE_HOME = $XANSIBLE_HOME

COPY --from=galaxy $ANSIBLE_HOME $ANSIBLE_HOME

RUN useradd -m $ANSIBLE_USER\
&& echo "$ANSIBLE_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers\
&& apt-get update\
&& apt-get install --no-install-recommends -y openssh-client\
&& apt-get install --no-install-recommends -y iputils-ping\
&& apt-get -qq clean\
&& rm -rf /var/lib/apt/lists/*

USER $ANSIBLE_USER
COPY --chown=$ANSIBLE_USER:$ANSIBLE_USER ansible.cfg $ANSIBLE_CONFIG

WORKDIR "/home/$ANSIBLE_USER"

# ENTRYPOINT ["/bin/bash","-c"]
# CMD ["su $ANSIBLE_USER"]
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 elhedhly
Copyright (c) 2024 H.Hedhly https://github.com/thehedhly

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
44 changes: 0 additions & 44 deletions README.md

This file was deleted.

16 changes: 16 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[defaults]
# playbook_dir = ./playbooks
roles_path = ~/.ansible/roles:./roles:/usr/share/ansible/roles
collections_path = ~/.ansible/collections:./collections:/usr/share/ansible/collections
bin_ansible_callbacks = True
callbacks_enabled = ansible.posix.profile_tasks
force_color = True
# Use the YAML callback plugin
stdout_callback = yaml

nocows = 1
# cow_selection = random
# cow_selection = small

[galaxy]
collections_path_warning = False
15 changes: 15 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

roles: []
# roles:
# - name: geerlingguy.go

Check warning on line 5 in requirements.yml

View workflow job for this annotation

GitHub Actions / lint

5:3 [comments-indentation] comment not indented like content
# version: "1.1.0"

# collections: []
collections:
- name: ansible.posix
version: ">=1.5.0"
- name: community.general
version: ">=8.1.0"
- name: community.docker
version: ">=3.5.0"

0 comments on commit bdb1075

Please sign in to comment.