Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Adds docker tests (#23)
Browse files Browse the repository at this point in the history
* Adds docker tests
  • Loading branch information
yxtay authored Dec 4, 2023
1 parent 19a6bc1 commit df08af0
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 34 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
restore-keys: |
${{ runner.os }}-pypoetry-${{ hashFiles('**/poetry.lock') }}
${{ runner.os }}-pypoetry-
- name: Create env file
run: |
touch .env
Expand All @@ -46,7 +46,7 @@ jobs:
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

Expand Down
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,23 @@ ARG ENVIRONMENT=dev
ENV ENVIRONMENT ${ENVIRONMENT}
CMD ["gunicorn", "src.web:app", "-c", "src/gunicorn_conf.py"]

##
# test
##
FROM dev AS test

USER root
RUN --mount=type=cache,target=${HOME}/.cache/pypoetry \
poetry install --no-root \
&& chown -R ${USER}:${USER} ${HOME} \
&& poetry show

USER ${USER}
COPY --chown=${USER}:${USER} tests tests
COPY --chown=${USER}:${USER} Makefile Makefile

CMD ["make", "lint", "test"]

##
# prod
##
Expand Down
77 changes: 45 additions & 32 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
version: "3.9"
services:
web_dev:
image: yxtay/python-project-template:dev
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
ENVIRONMENT: ${ENVIRONMENT:-dev}
cache_from:
- yxtay/python-project-template:dev
target: dev
volumes:
- .:/home/user/app
ports:
- "8000:8000"
env_file: .env
web:
image: yxtay/python-project-template:${IMAGE_TAG}
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
ENVIRONMENT: ${ENVIRONMENT:-dev}
cache_from:
- yxtay/python-project-template:dev
- yxtay/python-project-template:latest
- yxtay/python-project-template:${IMAGE_TAG}
target: prod
ports:
- "8000:8000"
env_file: .env
web_dev:
image: yxtay/python-project-template:dev
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
ENVIRONMENT: ${ENVIRONMENT:-dev}
cache_from:
- yxtay/python-project-template:dev
target: dev
volumes:
- .:/home/user/app
ports:
- "8000:8000"
env_file: .env
web_test:
image: yxtay/python-project-template:test
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
ENVIRONMENT: ${ENVIRONMENT:-dev}
cache_from:
- yxtay/python-project-template:dev
- yxtay/python-project-template:test
target: test
env_file: .env
web:
image: yxtay/python-project-template:${IMAGE_TAG}
build:
context: .
dockerfile: Dockerfile
args:
BUILDKIT_INLINE_CACHE: 1
ENVIRONMENT: ${ENVIRONMENT:-dev}
cache_from:
- yxtay/python-project-template:dev
- yxtay/python-project-template:latest
- yxtay/python-project-template:${IMAGE_TAG}
target: prod
ports:
- "8000:8000"
env_file: .env

0 comments on commit df08af0

Please sign in to comment.