diff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.yml new file mode 100644 index 0000000..bd8cca7 --- /dev/null +++ b/.github/workflows/ci_cd.yml @@ -0,0 +1,56 @@ +name: CI/CD + +on: [push, pull_request] + +permissions: read-all + +jobs: + setup: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + lint: + needs: setup + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run flake8 + run: | + pip install flake8 + flake8 . || true + + build: + needs: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Build Django app + run: | + python manage.py migrate + python manage.py collectstatic --noinput + + push: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Build and push Docker image + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/djangoline:latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..0a25f82 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,5 @@ +repos: + - repo: https://github.com/pycqa/flake8 + rev: 3.8.4 # The version of flake8 to use + hooks: + - id: flake8 diff --git a/my_site/Dockerfile b/my_site/Dockerfile index 2de388f..7f8d48f 100644 --- a/my_site/Dockerfile +++ b/my_site/Dockerfile @@ -2,5 +2,7 @@ FROM python:3.9-slim-buster WORKDIR /app COPY . /app RUN pip install -r requirements.txt +RUN pip install pre-commit +RUN pre-commit install CMD [ "python", "manage.py", "runserver", "0.0.0.0:8000" ] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..3930480 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flake8