Skip to content
This repository has been archived by the owner on Nov 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #31 from demokratie-live/2020/#828-kubernetes-setu…
Browse files Browse the repository at this point in the history
…p-cronjobs-bio-admin

switch to kubernetes
  • Loading branch information
ManAnRuck authored Jul 25, 2020
2 parents 72caabd + d6bef28 commit bd26788
Show file tree
Hide file tree
Showing 13 changed files with 544 additions and 338 deletions.
5 changes: 3 additions & 2 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
node_modules
npm-debug.log
.next/
.next
.env*
40 changes: 40 additions & 0 deletions .github/workflows/build-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Docker Image

on:
- push

jobs:
build:
name: Build Docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
submodules: true

- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo dev)"
id: extract_branch

# - name: Extract branch name
# shell: bash
# run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
# id: extract_branch

- name: Read package.json
uses: tyankatsu0105/read-package-version-actions@v1
id: package-version

- name: Extract repository name
shell: bash
run: echo "##[set-output name=REPOSITORY_NAME;]$(echo "$GITHUB_REPOSITORY" | awk -F / '{print $2}' | sed -e "s/:refs//")"
id: extract_repository

- uses: docker/build-push-action@v1
with:
username: ${{ github.actor }}
password: ${{ github.token }}
registry: docker.pkg.github.com
repository: ${{ github.repository }}/${{ steps.extract_repository.outputs.REPOSITORY_NAME }}
tags: ${{ steps.package-version.outputs.version }}-${{ steps.extract_branch.outputs.branch }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [2.1.2] - 2020-05-22

[Fix] Use token for bio-admin instead of whitelist ip

## [2.1.1] - 2020-05-19

[Added] HealthCheck (/health-check)

## [2.1.0] - 2019-10-30

### Changed
Expand Down
31 changes: 26 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
FROM node:12.11.1
FROM node:12-alpine AS BUILD_IMAGE

# TMP - Yarn fix
RUN mkdir -p /opt/yarn/bin && ln -s /opt/yarn/yarn-v1.5.1/bin/yarn /opt/yarn/bin/yarn
# install next-optimized-images requirements
RUN apk --no-cache update \
&& apk --no-cache add yarn curl g++ make bash zlib-dev libpng-dev python \
&& rm -fr /var/cache/apk/*

# install node-prune (https://github.com/tj/node-prune)
RUN curl -sfL https://install.goreleaser.com/github.com/tj/node-prune.sh | bash -s -- -b /usr/local/bin

WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn --frozen-lockfile
COPY . .

RUN yarn build

RUN npm prune --production

# run node prune
RUN /usr/local/bin/node-prune

FROM node:12-alpine

WORKDIR /app

COPY . .

RUN yarn install
# copy from build image
COPY --from=BUILD_IMAGE /app/.next ./.next
COPY --from=BUILD_IMAGE /app/node_modules ./node_modules

RUN yarn build
ENV NODE_ENV=production

ENTRYPOINT [ "yarn", "start" ]
18 changes: 18 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM node:12-alpine

# install next-optimized-images requirements
RUN apk --no-cache update \
&& apk --no-cache add yarn curl g++ make bash zlib-dev libpng-dev python \
&& rm -fr /var/cache/apk/*

WORKDIR /app

COPY package.json yarn.lock ./

RUN yarn --frozen-lockfile

COPY . .

ENV NODE_ENV=development

ENTRYPOINT [ "yarn", "dev" ]
47 changes: 47 additions & 0 deletions components/Procedures/PlenarText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'

const replaceText = (text, strPart, color) => {
return text.replaceAll(strPart, `<span style="background-color: ${color}">${strPart}</span>`)
}

const replaceParties = (text) => {
let outText = [
["Grüne", "#abffb3"],
["Linke", "#fa9db0"],
["CDU", "#d1c9ca"],
["CSU", "#d1c9ca"],
["Union", "#d1c9ca"],
["FDP", "#f8ffa6"],
["AfD", "#94fff8"],
["SPD", "#fab59d"],
["alle übrigen", "#ffe1a1"],
].reduce((prev, p) => {
return replaceText(prev, p[0], p[1])
}, text)
return outText;
}

const replaceVoteKeywords = (text) => {
const returnText = ["abgelehnt", "angenommen"].reduce((prev, docId) => {
return replaceText(prev, docId, "#ff42e0")
}, text)
return returnText;
}

const replaceDocNumbers = (text, docIds) => {
const returnText = docIds.reduce((prev, docId) => {
return replaceText(prev, docId, "#ff42e0")
}, text)
return returnText;
}

const PlenarText = ({text, docIds}) => {
let outText = replaceParties(text);
outText = replaceVoteKeywords(outText);
outText = replaceDocNumbers(outText, docIds);
return (
<div dangerouslySetInnerHTML={{__html: outText }} style={{paddingBottom: "10px"}} />
)
}

export default PlenarText
3 changes: 2 additions & 1 deletion graphql/mutations/saveVoteResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import gql from "graphql-tag";
import VoteResults from "../fragments/voteResults";

export default gql`
mutation saveProcedureCustomData(
$procedureId: String!
$partyVotes: [PartyVoteInput!]!
$decisionText: String!
$votingDocument: String!
$votingDocument: VotingDocument!
) {
saveProcedureCustomData(
procedureId: $procedureId
Expand Down
1 change: 0 additions & 1 deletion graphql/queries/procedureList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const proceduresQuery = gql`
period
currentStatus
namedVote
bioUpdateAt
importantDocuments {
type
editor
Expand Down
9 changes: 9 additions & 0 deletions graphql/queries/voteTexts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import gql from "graphql-tag";

export default gql`
query voteTexts($procedureId: String!) {
voteResultTextHelper(procedureId: $procedureId) {
results
}
}
`;
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "with-apollo",
"version": "2.1.0",
"name": "bundestag.io-admin",
"version": "2.1.8",
"scripts": {
"dev": "node -r dotenv/config server.js",
"build": "next build",
Expand All @@ -14,6 +14,7 @@
"antd": "^3.6.5",
"apollo-boost": "^0.1.3",
"babel-plugin-import": "^1.8.0",
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"basic-auth-connect": "^1.0.0",
"dotenv": "^8.2.0",
"express": "^4.16.3",
Expand All @@ -29,13 +30,12 @@
"react-infinite-scroller": "^1.2.0",
"request": "^2.88.0",
"styled-components": "^4.4.1",
"webpack-bundle-analyzer": "^2.13.1",
"yup": "^0.26.0"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-plugin-transform-decorators-legacy": "^1.3.5",
"cross-env": "^5.2.0",
"webpack-bundle-analyzer": "^2.13.1"
"cross-env": "^5.2.0"
}
}
70 changes: 51 additions & 19 deletions pages/procedure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { withRouter } from "next/router";
import { graphql, compose } from "react-apollo";
import styled from "styled-components";
import Link from "next/link";
import { Form, Input, Button, Popconfirm, notification } from "antd";
import { Form, Input, Collapse } from "antd";

const { Panel } = Collapse;

import {PROCEDURE as PROCEDURE_DEFINITIONS} from '@democracy-deutschland/bundestag.io-definitions';

import VoteResultsForm from "../components/Procedures/VoteResultsForm";

// GraphQL
import PROCEDURE from "../graphql/queries/procedure";
import VOTE_TEXTS from "../graphql/queries/voteTexts";
import PlenarText from "../components/Procedures/PlenarText";

// Ant Design Sub-Elements
const { TextArea } = Input;
Expand All @@ -38,6 +42,7 @@ const Procedure = props => {
history,
customData,
namedVote,
voteResultTextHelper
} = props;

if (loadingProcedure) {
Expand Down Expand Up @@ -106,6 +111,18 @@ const Procedure = props => {
</>
)}
</dl>
{!!voteResultTextHelper && voteResultTextHelper.length > 0 && (
<Collapse>
{voteResultTextHelper.map(({results}, i) => {
return (
<Panel header={`📚 ${results[1].substr(0, 50)}`} key={i}>
{results.map((value, i) => (
<PlenarText key={i} text={value} docIds={importantDocuments.map(({number}) => number)} />
))}
</Panel>)
})}
</Collapse>
)}
{!namedVote &&
<VoteResultsForm
data={customData.voteResults}
Expand All @@ -120,26 +137,41 @@ const Procedure = props => {

export default withRouter(
compose(
graphql(PROCEDURE, {
options: ({ router: { query } }) => {
return {
variables: {
procedureId: query.id
},
fetchPolicy: "cache-and-network"
};
},
props: ({ data: { loading, procedure, ...data } }) => {
if (loading) {
graphql(PROCEDURE, {
options: ({ router: { query } }) => {
return {
loadingProcedure: loading
variables: {
procedureId: query.id
},
fetchPolicy: "cache-and-network"
};
},
props: ({ data: { loading, procedure, ...data } }) => {
if (loading) {
return {
loadingProcedure: loading
};
}
return {
loadingProcedure: loading,
...procedure
};
}
return {
loadingProcedure: loading,
...procedure
};
}
}),
}),
graphql(VOTE_TEXTS, {
options: ({ router: { query } }) => {
return {
variables: {
procedureId: query.id
},
fetchPolicy: "cache-and-network"
};
},
props: ({ data: { voteResultTextHelper } }) => {
return {
voteResultTextHelper
};
}
}),
)(Procedure)
);
12 changes: 10 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require("express");
const next = require("next");
var basicAuth = require("basic-auth-connect");
const request = require("request")

// require("./lib/parseOpenDataXml");

Expand All @@ -16,15 +17,22 @@ app
.then(() => {
const server = express();

server.get("/health-check", (req, res) => {
res.status(200).send("ok")
});

if (!dev) {
console.log("ADMIN_USER:", process.env.ADMIN_USER.replace(/./g, '*'))
console.log("ADMIN_PASSWORD:", process.env.ADMIN_PASSWORD.replace(/./g, '*'))
server.use(basicAuth(process.env.ADMIN_USER, process.env.ADMIN_PASSWORD));
}

server.all("/graphql", (req, res) => {
console.log("HOHO")
const url = process.env.BUNDESTAGIO_SERVER_URL;
const request = require("request")
return req.pipe(request({ qs: req.query, uri: url }).on('error', function (err) {
return req.pipe(request({ qs: req.query, uri: url, headers: {
"bio-auth-token": process.env.BIO_EDIT_TOKEN
} }).on('error', function (err) {
console.info(err);
return res.sendStatus(400);
}))
Expand Down
Loading

0 comments on commit bd26788

Please sign in to comment.