diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index e0e56c683..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,230 +0,0 @@ -name: passbook-ci -on: - - push -env: - POSTGRES_DB: passbook - POSTGRES_USER: passbook - POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" - -jobs: - # Linting - pylint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev - - name: Lint with pylint - run: pipenv run pylint passbook - black: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev - - name: Lint with black - run: pipenv run black --check passbook - prospector: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev && pipenv install --dev prospector --skip-lock - - name: Lint with prospector - run: pipenv run prospector - bandit: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev - - name: Lint with bandit - run: pipenv run bandit -r passbook - snyk: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@master - - name: Run Snyk to check for vulnerabilities - uses: snyk/actions/python@master - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} - pyright: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-node@v1 - with: - node-version: '12' - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install pyright - run: npm install -g pyright - - name: Show pyright version - run: pyright --version - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev - - name: Lint with pyright - run: pipenv run pyright - # Actual CI tests - migrations: - needs: - - pylint - - black - - prospector - services: - postgres: - image: postgres:latest - env: - POSTGRES_DB: passbook - POSTGRES_USER: passbook - POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" - ports: - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - name: Install dependencies - run: sudo pip install -U wheel pipenv && pipenv install --dev - - name: Run migrations - run: pipenv run ./manage.py migrate - coverage: - needs: - - pylint - - black - - prospector - services: - postgres: - image: postgres:latest - env: - POSTGRES_DB: passbook - POSTGRES_USER: passbook - POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" - ports: - - 5432:5432 - redis: - image: redis:latest - ports: - - 6379:6379 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - uses: actions/setup-python@v1 - with: - python-version: '3.8' - - uses: actions/setup-node@v1 - with: - node-version: '12' - - name: Install dependencies - run: | - sudo pip install -U wheel pipenv - pipenv install --dev - - name: Prepare Chrome node - run: | - cd e2e - docker-compose pull -q chrome - docker-compose up -d chrome - - name: Build static files for e2e test - run: | - cd passbook/static/static - yarn - - name: Run coverage - run: pipenv run coverage run ./manage.py test --failfast - - uses: actions/upload-artifact@v2 - if: failure() - with: - path: selenium_screenshots/ - - name: Create XML Report - run: pipenv run coverage xml - - uses: codecov/codecov-action@v1 - with: - token: ${{ secrets.CODECOV_TOKEN }} - # Build - build-server: - needs: - - migrations - - coverage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Docker Login Registry - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - - name: Building Docker Image - run: docker build - --no-cache - -t beryju/passbook:gh-${GITHUB_REF##*/} - -f Dockerfile . - - name: Push Docker Container to Registry - run: docker push beryju/passbook:gh-${GITHUB_REF##*/} - build-gatekeeper: - needs: - - migrations - - coverage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Docker Login Registry - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - - name: Building Docker Image - run: | - cd gatekeeper - docker build \ - --no-cache \ - -t beryju/passbook-gatekeeper:gh-${GITHUB_REF##*/} \ - -f Dockerfile . - - name: Push Docker Container to Registry - run: docker push beryju/passbook-gatekeeper:gh-${GITHUB_REF##*/} - build-static: - needs: - - migrations - - coverage - runs-on: ubuntu-latest - services: - postgres: - image: postgres:latest - env: - POSTGRES_DB: passbook - POSTGRES_USER: passbook - POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" - redis: - image: redis:latest - steps: - - uses: actions/checkout@v1 - - name: Docker Login Registry - env: - DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} - run: docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD - - name: Building Docker Image - run: docker build - --no-cache - --network=$(docker network ls | grep github | awk '{print $1}') - -t beryju/passbook-static:gh-${GITHUB_REF##*/} - -f static.Dockerfile . - - name: Push Docker Container to Registry - run: docker push beryju/passbook-static:gh-${GITHUB_REF##*/} diff --git a/README.md b/README.md index 33d7dd192..0502e5009 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ passbook logopassbook -![CI Build status](https://img.shields.io/github/workflow/status/beryju/passbook/passbook-ci?style=flat-square) +======= +![CI Build status](https://img.shields.io/azure-devops/build/beryjuorg/5d94b893-6dea-4f68-a8fe-10f1674fc3a9/1?style=flat-square) ![Docker pulls](https://img.shields.io/docker/pulls/beryju/passbook.svg?style=flat-square) ![Docker pulls (gatekeeper)](https://img.shields.io/docker/pulls/beryju/passbook-gatekeeper.svg?style=flat-square) ![Latest version](https://img.shields.io/docker/v/beryju/passbook?sort=semver&style=flat-square) @@ -50,31 +51,7 @@ pipenv sync -d ``` Since passbook uses PostgreSQL-specific fields, you also need a local PostgreSQL instance to develop. passbook also uses redis for caching and message queueing. -For these databases you can use [Postgres.app](https://postgresapp.com/) and [Redis.app](https://jpadilla.github.io/redisapp/) on macOS or use it via docker-comppose: - -```yaml -version: '3.7' - -services: - postgresql: - container_name: postgres - image: postgres:11 - volumes: - - db-data:/var/lib/postgresql/data - ports: - - 127.0.0.1:5432:5432 - restart: always - redis: - container_name: redis - image: redis - ports: - - 127.0.0.1:6379:6379 - restart: always - -volumes: - db-data: - driver: local -``` +For these databases you can use [Postgres.app](https://postgresapp.com/) and [Redis.app](https://jpadilla.github.io/redisapp/) on macOS or use it the docker-compose file in `scripts/docker-compose.yml`. To tell passbook about these databases, create a file in the project root called `local.env.yml` with the following contents: diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 000000000..b0107ddbe --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,230 @@ +trigger: + - master + +resources: + - repo: self + +variables: + POSTGRES_DB: passbook + POSTGRES_USER: passbook + POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" + +stages: + - stage: Lint + jobs: + - job: pylint + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: CmdLine@2 + inputs: + script: pipenv run pylint passbook + - job: black + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: CmdLine@2 + inputs: + script: pipenv run black --check passbook + - job: prospector + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + pipenv install --dev prospector --skip-lock + - task: CmdLine@2 + inputs: + script: pipenv run prospector passbook + - job: bandit + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: CmdLine@2 + inputs: + script: pipenv run bandit -r passbook + - job: pyright + pool: + vmImage: ubuntu-latest + steps: + - task: UseNode@1 + inputs: + version: '12.x' + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: CmdLine@2 + inputs: + script: npm install -g pyright + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: CmdLine@2 + inputs: + script: pipenv run pyright + - stage: Test + jobs: + - job: migrations + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: DockerCompose@0 + displayName: Run services + inputs: + dockerComposeFile: 'scripts/docker-compose.yml' + action: 'Run services' + buildImages: false + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: CmdLine@2 + inputs: + script: pipenv run ./manage.py migrate + - job: coverage + pool: + vmImage: 'ubuntu-latest' + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: '3.8' + - task: DockerCompose@0 + displayName: Run services + inputs: + dockerComposeFile: 'scripts/docker-compose.yml' + action: 'Run services' + buildImages: false + - task: CmdLine@2 + inputs: + script: | + sudo pip install -U wheel pipenv + pipenv install --dev + - task: DockerCompose@0 + displayName: Run ChromeDriver + inputs: + dockerComposeFile: 'e2e/docker-compose.yml' + action: 'Run a specific service' + serviceName: 'chrome' + - task: CmdLine@2 + displayName: Build static files for e2e + inputs: + script: | + cd passbook/static/static + yarn + - task: CmdLine@2 + displayName: Run full test suite + inputs: + script: pipenv run coverage run ./manage.py test --failfast + - task: PublishBuildArtifacts@1 + condition: failed() + displayName: Upload screenshots if selenium tests fail + inputs: + PathtoPublish: 'selenium_screenshots/' + ArtifactName: 'drop' + publishLocation: 'Container' + - task: CmdLine@2 + inputs: + script: | + pipenv run coverage xml + pipenv run coverage html + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: 'coverage.xml' + - task: PublishTestResults@2 + condition: succeededOrFailed() + inputs: + testRunTitle: 'Publish test results for Python $(python.version)' + testResultsFiles: 'unittest.xml' + - task: CmdLine@2 + env: + CODECOV_TOKEN: $(CODECOV_TOKEN) + inputs: + script: bash <(curl -s https://codecov.io/bash) + - stage: Build + jobs: + - job: build_server + pool: + vmImage: 'ubuntu-latest' + steps: + - task: Docker@2 + inputs: + containerRegistry: 'dockerhub' + repository: 'beryju/passbook' + command: 'buildAndPush' + Dockerfile: 'Dockerfile' + tags: 'gh-$(Build.SourceBranchName)' + - job: build_gatekeeper + pool: + vmImage: 'ubuntu-latest' + steps: + - task: CmdLine@2 + inputs: + script: cd gatekeeper + - task: Docker@2 + inputs: + containerRegistry: 'dockerhub' + repository: 'beryju/passbook-gatekeeper' + command: 'buildAndPush' + Dockerfile: 'Dockerfile' + tags: 'gh-$(Build.SourceBranchName)' + - job: build_static + pool: + vmImage: 'ubuntu-latest' + steps: + - task: DockerCompose@0 + displayName: Run services + inputs: + dockerComposeFile: 'scripts/docker-compose.yml' + action: 'Run services' + buildImages: false + - task: Docker@2 + inputs: + containerRegistry: 'dockerhub' + repository: 'beryju/passbook-static' + command: 'build' + Dockerfile: 'static.Dockerfile' + tags: 'gh-$(Build.SourceBranchName)' + arguments: "--network=beryjupassbook_default" + - task: Docker@2 + inputs: + containerRegistry: 'dockerhub' + repository: 'beryju/passbook-static' + command: 'push' + tags: 'gh-$(Build.SourceBranchName)' diff --git a/scripts/docker-compose.yml b/scripts/docker-compose.yml new file mode 100644 index 000000000..ed841bce5 --- /dev/null +++ b/scripts/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + postgresql: + container_name: postgres + image: postgres:11 + volumes: + - db-data:/var/lib/postgresql/data + environment: + POSTGRES_DB: passbook + POSTGRES_USER: passbook + POSTGRES_PASSWORD: "EK-5jnKfjrGRm<77" + ports: + - 5432:5432 + restart: always + redis: + container_name: redis + image: redis + ports: + - 6379:6379 + restart: always + +volumes: + db-data: + driver: local