-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
102 lines (80 loc) · 3.04 KB
/
Dockerfile
File metadata and controls
102 lines (80 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#############
# Dependencies
#
# This base stage just installs the dependencies required for production
# without any development deps.
ARG PYTHON_VER=3.12
FROM python:${PYTHON_VER} AS base
# Allow for flexible Python versions, for broader testing
ENV PYTHON_VERSION=${PYTHON_VER}
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install --no-install-recommends -y pkg-config build-essential && \
apt-get autoremove -y && \
apt-get clean all && \
rm -rf /var/lib/apt/lists/* && \
pip --no-cache-dir install --upgrade pip wheel
WORKDIR /usr/src/app
# Install uv for dependency management
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Put the virtualenv on PATH so ansible-galaxy, ansible-test, etc. are available
ENV PATH="/usr/src/app/.venv/bin:$PATH"
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install dependencies
RUN uv sync --frozen --no-dev --no-install-project
# Copy in the application source and everything not explicitly banned by .dockerignore
COPY . .
############
# Sanity Tests
FROM base AS sanity
# Set a custom collection path for all ansible commands
# Note: This only allows for one path, not colon-separated, because we use it
# elsewhere
ARG ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
ENV ANSIBLE_COLLECTIONS_PATH=${ANSIBLE_COLLECTIONS_PATH}
ARG PYTHON_VER=3.12
ENV PYTHON_VERSION=${PYTHON_VER}
# Allows for custom command line arguments to be passed to ansible-test (like -vvv)
ARG ANSIBLE_SANITY_ARGS
ENV ANSIBLE_SANITY_ARGS=${ANSIBLE_SANITY_ARGS}
# For Module unit tests as we use some testing features avaiable in this collection
RUN ansible-galaxy collection install community.general
# Build Collection to run ansible-tests against
RUN ansible-galaxy collection build --output-path ./dist/ .
# Install built library
RUN ansible-galaxy collection install ./dist/opsmill-infrahub*.tar.gz -p ${ANSIBLE_COLLECTIONS_PATH}
# Switch to the collection path for tests
WORKDIR ${ANSIBLE_COLLECTIONS_PATH}/ansible_collections/opsmill/infrahub
# Run sanity tests
RUN ansible-test sanity $ANSIBLE_SANITY_ARGS \
--requirements \
--skip-test pep8 \
--python ${PYTHON_VERSION} \
plugins/
############
# Unit Tests
FROM base AS unittests
# Set a custom collection path for all ansible commands
# Note: This only allows for one path, not colon-separated, because we use it
# elsewhere
ARG ANSIBLE_COLLECTIONS_PATH=/usr/share/ansible/collections
ENV ANSIBLE_COLLECTIONS_PATH=${ANSIBLE_COLLECTIONS_PATH}
ARG PYTHON_VER=3.12
ENV PYTHON_VERSION=${PYTHON_VER}
# Allows for custom command line arguments to be passed to ansible-test (like -vvv)
ARG ANSIBLE_UNIT_ARGS
ENV ANSIBLE_UNIT_ARGS=${ANSIBLE_UNIT_ARGS}
# Run unit tests
# RUN ansible-test units $ANSIBLE_UNIT_ARGS --coverage --python ${PYTHON_VERSION}
############
# Integration Tests
FROM base AS integration
ARG ANSIBLE_INTEGRATION_ARGS
ENV ANSIBLE_INTEGRATION_ARGS=${ANSIBLE_INTEGRATION_ARGS}
ARG PYTHON_VER=3.12
ENV PYTHON_VERSION=${PYTHON_VER}
# Run Integration tests
# RUN <SOMETHING>
# CMD ["--help"]