Skip to content

Commit

Permalink
Convert to flask
Browse files Browse the repository at this point in the history
  • Loading branch information
solazio committed Apr 23, 2020
1 parent 6e4302f commit a2cffda
Show file tree
Hide file tree
Showing 42 changed files with 5,115 additions and 1,271 deletions.
78 changes: 68 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: 2

defaults: &defaults
docker:
- image: canonicalwebteam/dev
- image: canonicalwebteam/dev:v1.6.7
environment:
SECRET_KEY: local_development_fake_key

jobs:
test-site:
Expand All @@ -11,27 +13,44 @@ jobs:
- checkout
- run:
name: Install dependencies
command: yarn && bundle install --path vendor/bundle
command: yarn && pip3 install -r requirements.txt
- run:
name: Build the site resources
command: yarn run build
- run:
name: Run the site server
command: bundle exec jekyll serve -P 80 -H 0.0.0.0
command: ./entrypoint 0.0.0.0:80
background: true
- run:
name: Check site is accessible
command: sleep 3 && curl --head --fail --retry-delay 5 --retry 10 --retry-connrefused http://localhost
lint-nginx:
linkchecker:
<<: *defaults
steps:
- checkout
- run:
name: Install gixy
command: pip3 install gixy
name: Yarn install
command: yarn install
- run:
name: Lint nginx configuration files
command: gixy nginx.conf
name: Yarn build
command: yarn build
- run:
name: Install dependencies
command: pip3 install -r requirements.txt
- run:
name: Start development server
command: ./entrypoint 0.0.0.0:80
background: true
- run:
name: Wait for development server
command: sleep 5
lint-python:
<<: *defaults
steps:
- checkout
- run:
name: Lint python code
command: yarn lint-python
lint-scss:
<<: *defaults
steps:
Expand All @@ -42,11 +61,50 @@ jobs:
- run:
name: Lint sass
command: yarn lint-scss

lint-js:
<<: *defaults
steps:
- checkout
- run:
name: Install dependencies
command: yarn
- run:
name: Lint JS
command: yarn lint-js
test-python:
<<: *defaults
steps:
- checkout
- run:
name: Install dependencies
command: yarn && pip3 install -r requirements.txt
- run:
name: Build the site resources
command: yarn run build
- run:
name: Install coverage
command: pip3 install coverage
- run:
name: Run tests with coverage
command: |
coverage run --source=. -m unittest discover tests
bash <(curl -s https://codecov.io/bash) -cF python
test-js:
<<: *defaults
steps:
- checkout
- run:
name: Install dependencies
command: yarn
- run:
name: Run tests with jest
command: yarn run test-js
workflows:
version: 2
build:
jobs:
- test-site
- lint-nginx
- lint-scss
- lint-js
- lint-python
- test-python
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
PORT=8037
FLASK_DEBUG=true
SECRET_KEY=local_development_fake_key

20 changes: 20 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
parser: "babel-eslint",
globals: {},
env: {
browser: true,
es6: true
},
extends: [
"eslint:recommended",
"plugin:prettier/recommended"
],
parserOptions: {
sourceType: "module",
},
rules: {
"linebreak-style": ["error", "unix"],
semi: ["error", "always"],
"object-curly-spacing": ["error", "always"]
}
};
20 changes: 20 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Done

[List of work items including drive-bys]

## QA

- Check out this feature branch
- Run the site using the command `./run serve`
- View the site locally in your web browser at: http://0.0.0.0:8037
- Run through the following [QA steps](https://canonical-web-and-design.github.io/practices/workflow/qa-steps.html)
- [List additional steps to QA the new features or prove the bug has been resolved]


## Issue / Card

Fixes #

## Screenshots

[if relevant, include a screenshot]
16 changes: 13 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# [generated] Bracketed sections updated by Yeoman generator
# generator-canonical-webteam@2.5.0
# generator-canonical-webteam@3.4.1

# [os] OS & editor files
Desktop.ini
Expand Down Expand Up @@ -41,6 +41,7 @@ package-lock.json
/parts/
/prime/
/stage/
*.egg-info
.snapcraft/
*.snap
_site/
Expand All @@ -53,10 +54,19 @@ _site/
.env.local
env/
env[23]/
virtual/
venv/

# [sass] Files generated by Sass
*.css

# Project-specific ignores
js/build
# dotrun snap files
.dotrun.json
.venv/

node_modules/
bower_components/
*.log

build/
dist/
1 change: 0 additions & 1 deletion .stylelintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"plugins": [
"stylelint-order"
],
"ignoreFiles": ["static/sass/_hljs.scss"],
"rules": {
"order/properties-alphabetical-order": true,
"at-rule-no-unknown": [ true, {
Expand Down
62 changes: 13 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,57 +1,21 @@
# syntax=docker/dockerfile:experimental

# Build stage: Install ruby dependencies
# ===
FROM ruby:2.5 AS build-site
WORKDIR /srv
ADD . .
RUN bundle install
RUN bundle exec jekyll build

# Build stage: Install yarn dependencies
# ===
FROM node:12-slim AS yarn-dependencies
WORKDIR /srv
ADD package.json .
RUN --mount=type=cache,target=/usr/local/share/.cache/yarn yarn install

# Build stage: Run "yarn run build-js"
# ===
FROM yarn-dependencies AS build-js
WORKDIR /srv
COPY . .
RUN yarn run build-js

# Build stage: Run "yarn run build-css"
# ===
FROM yarn-dependencies AS build-css
WORKDIR /srv
COPY . .
RUN yarn run build-css

# Build the production image
# ===
FROM ubuntu:focal
FROM ubuntu:bionic

# Set up environment
ENV LANG C.UTF-8
WORKDIR /srv

# Install nginx
RUN apt-get update && apt-get install --no-install-recommends --yes nginx

# Import code, build assets and mirror list
RUN rm -rf package.json yarn.lock .babelrc webpack.config.js Gemfile.lock nginx.conf
COPY --from=build-site srv/_site .
COPY --from=build-css srv/css css
COPY --from=build-js srv/js js
# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends python3 python3-setuptools python3-pip

ARG BUILD_ID
ADD nginx.conf /etc/nginx/sites-enabled/default
RUN sed -i "s/~BUILD_ID~/${BUILD_ID}/" /etc/nginx/sites-enabled/default

STOPSIGNAL SIGTERM

CMD ["nginx", "-g", "daemon off;"]
# Set git commit ID
ARG COMMIT_ID
ENV COMMIT_ID "${COMMIT_ID}"
ENV TALISKER_REVISION_ID "${COMMIT_ID}"

# Import code, install code dependencies
COPY . .
RUN python3 -m pip install --no-cache-dir -r requirements.txt

# Setup commands to run server
ENTRYPOINT ["./entrypoint"]
CMD ["0.0.0.0:80"]
27 changes: 0 additions & 27 deletions Gemfile

This file was deleted.

70 changes: 0 additions & 70 deletions Gemfile.lock

This file was deleted.

Loading

0 comments on commit a2cffda

Please sign in to comment.