Skip to content

Commit

Permalink
Merge pull request #767 from openva/deploy
Browse files Browse the repository at this point in the history
Sync deploy
  • Loading branch information
waldoj authored Jan 8, 2024
2 parents cc34456 + ab71ff4 commit 381352d
Show file tree
Hide file tree
Showing 110 changed files with 909 additions and 578 deletions.
22 changes: 15 additions & 7 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ on:
- master
- deploy
pull_request:
schedule:
- cron: 0 4 * * * # Redeploy at 4 AM every day

jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: Firenza/secrets-to-env@v1.1.0
- uses: Firenza/secrets-to-env@v1.2.0
with:
secrets: ${{ toJSON(secrets) }}
- name: Specify PHP version
Expand All @@ -23,7 +25,7 @@ jobs:
- run: >-
sudo apt-get update &&
sudo apt-get install -y awscli php5.6-cli php5.6-curl php5.6-memcached php5.6-mysql yarn zip
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: sudo apt-get update -qq
- run: composer install
- run: cd htdocs/js/vendor; yarn build
Expand All @@ -44,7 +46,7 @@ jobs:
cp appspec-deploy.yml appspec.yml
fi
- name: Save secret-populated code for a subsequent deploy step
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: codebase
path: .
Expand All @@ -61,28 +63,34 @@ jobs:
steps:
- run: echo "Deploy branch is ${{ needs.build.outputs.github_branch }}"
- name: Get the secret-populated code
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: codebase
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-east-1
- name: Staging CodeDeploy Deployment
if: ${{ needs.build.outputs.github_branch == 'master' }}
run: |
aws deploy push --application-name RS-Web \
--s3-location s3://deploy.richmondsunlight.com/rs-web-staging.zip \
--ignore-hidden-files
aws deploy create-deployment \
--application-name RS-Web \
--deployment-group-name RS-Web-Staging \
--deployment-config-name CodeDeployDefault.OneAtATime \
--github-location repository=${{ github.repository }},commitId=${{ github.sha }}
--s3-location bucket=deploy.richmondsunlight.com,key=rs-web-staging.zip,bundleType=zip
- name: Production CodeDeploy Deployment
if: ${{ needs.build.outputs.github_branch == 'deploy' }}
run: |
aws deploy push --application-name RS-Web \
--s3-location s3://deploy.richmondsunlight.com/rs-web-deploy.zip \
--ignore-hidden-files
aws deploy create-deployment \
--application-name RS-Web \
--deployment-group-name RS-Web-Fleet \
--deployment-config-name CodeDeployDefault.OneAtATime \
--github-location repository=${{ github.repository }},commitId=${{ github.sha }}
--s3-location bucket=deploy.richmondsunlight.com,key=rs-web-deploy.zip,bundleType=zip
4 changes: 0 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
"doctrine/instantiator":"1",
"simplepie/simplepie": "1.5.5",
"romainneutron/sphinx-search-api-php-client": "2.0.8.1",
"tijsverkoyen/akismet": "~1",
"aws/aws-sdk-php": "~3.186"
},
"autoload": {
"psr-4": {
"TijsVerkoyen\\": "htdocs/includes/vendor/tijsverkoyen/"
},
"classmap": [
"htdocs/includes/vendor/"
],
Expand Down
46 changes: 1 addition & 45 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions deploy/config_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ variables=(
PDO_PASSWORD
MYSQL_DATABASE
GMAPS_KEY
GEOPARSER_KEY
OPENSTATES_KEY
OPENVA_KEY
VA_DECODED_KEY
MAPBOX_TOKEN
AKISMET_KEY
MEMCACHED_SERVER
PUSHOVER_KEY
OPENAI_KEY
SLACK_WEBHOOK
API_URL
AWS_SES_SMTP_USERNAME
Expand Down
79 changes: 58 additions & 21 deletions deploy/generate-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,53 +28,90 @@
foreach ($legislator_list as $legislator)
{

$legislators[$legislator{'chamber'}][substr($legislator{'name'}, 0, 1)][] = '<li><a href="/legislator/' . $legislator['shortname']
. '/">' . $legislator['name_formatted'] . '</a></li>';
$legislators[$legislator{'chamber'}][substr($legislator{'name'}, 0, 1)][] = '<a href="/legislator/' . $legislator['shortname']
. '/">' . $legislator['name_formatted'] . '</a>';

}

/*
* Establish our alphabetical groupings
*/
$house_categories = explode(',', 'a,i,d,m,s');
$senate_categories = explode(',', 'a,n');
$alphabet = explode(',', 'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z');
$house_categories = explode(',', 'A,I,D,M,S');
$senate_categories = explode(',', 'A,J,S');

////////////////////////////////////////////////////////////////////////
///// Redo this to be based on iterating through the alphabet, NOT
///// iterating through the list of legislators. Missing alphabetical
///// letters from legislators names is hobbling this.
////////////////////////////////////////////////////////////////////////

/*
* Output menu data
*/
echo '
<ul>
<li>House »
<ul class="alphabetic">
<li>A–Z »
<ul class="legislators">';
<ul class="alphabetic">';

$first = true;
foreach ($legislators['house'] as $letter => $by_letter)
{
echo '<li>' . $letter . ' »
<ul class="legislators">';

if (in_array($letter, $house_categories) || $first == true)
{
echo
'<li>' . $letter . ' »
<ul class="legislators">';
}

foreach ($by_letter as $legislator)
{
echo '<li>' . $legislator . '</li>';
echo '
<li>' . $legislator . '</li>';
}

if (in_array($alphabet[array_search($letter, $alphabet)]+1, $house_categories))
{
echo '
</ul></li>';
}
echo '</ul></li>';

$first = false;

}

echo '
</li>
<li>Senate »
<ul class="alphabetic">';

foreach ($legislators['senate'] as $letter => $by_letter)
{
echo '<li>' . $letter . ' »
<ul class="legislators">';
foreach ($by_letter as $legislator)
{
echo '<li>' . $legislator . '</li>';
}
echo '</ul></li>';
}
$first = true;
foreach ($legislators['senate'] as $letter => $by_letter)
{

if (in_array($letter, $senate_categories) || $first == true)
{
echo '
<li>' . $letter . ' »
<ul class="legislators">';
}

foreach ($by_letter as $legislator)
{
echo '
<li>' . $legislator . '</li>';
}

if (in_array($alphabet[array_search($letter, $alphabet)]+1, $senate_categories))
{
echo '
</ul></li>';
}

$first = false;

}

echo '
</ul>
Expand Down
7 changes: 4 additions & 3 deletions deploy/mysql/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,7 @@ CREATE TABLE `districts` (
`date_started` date NOT NULL,
`date_ended` date NOT NULL,
`description` varchar(300) CHARACTER SET latin1 DEFAULT NULL,
`boundaries` json DEFAULT NULL,
`notes` text CHARACTER SET latin1,
`date_modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_created` datetime NOT NULL,
Expand Down Expand Up @@ -2598,7 +2599,7 @@ DROP TABLE IF EXISTS `gazetteer`;
CREATE TABLE `gazetteer` (
`id` mediumint(8) unsigned NOT NULL,
`name` varchar(128) CHARACTER SET utf8 NOT NULL,
`municipality` varchar(64) CHARACTER SET utf8 NOT NULL,
`municipality` varchar(64) CHARACTER SET utf8,
`latitude` float NOT NULL,
`longitude` float NOT NULL,
`elevation` tinyint(3) unsigned DEFAULT NULL,
Expand Down Expand Up @@ -3120,7 +3121,7 @@ CREATE TABLE `representatives` (
`rss_url` varchar(64) CHARACTER SET latin1 DEFAULT NULL,
`twitter` varchar(96) CHARACTER SET latin1 DEFAULT NULL,
`sbe_id` varchar(11) COLLATE utf8_bin DEFAULT NULL,
`lis_id` smallint(5) unsigned DEFAULT NULL,
`lis_id` varchar(10) unsigned DEFAULT NULL,
`place` varchar(60) CHARACTER SET latin1 DEFAULT NULL COMMENT 'District office location',
`latitude` float DEFAULT NULL,
`longitude` float DEFAULT NULL,
Expand Down Expand Up @@ -3875,7 +3876,7 @@ DROP TABLE IF EXISTS `tags`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tags` (
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(5) unsigned NOT NULL,
`user_id` int(5) unsigned,
`bill_id` mediumint(8) unsigned NOT NULL,
`tag` varchar(30) CHARACTER SET latin1 NOT NULL,
`ip` varchar(19) CHARACTER SET latin1 DEFAULT NULL,
Expand Down
40 changes: 40 additions & 0 deletions deploy/populate_menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* Define file names
*/
$template_file = 'htdocs/includes/templates/new.inc.php';
$legislator_menu_file = 'htdocs/includes/templates/legislators.html';

/*
* Make sure the files exist
*/
if (!file_exists($template_file))
{
echo 'Error: ' . $FILE_TO_EDIT . ' template is missing, cannot insert legislators menu.' . "\n";
exit(1);
}
elseif (!file_exists($legislator_menu_file))
{
echo 'Error: ' . $REPLACEMENT_FILE . ' is missing, cannot insert into template.' . "\n";
exit(1);
}

/*
* Get the contents of both files
*/
$legislator_menu = file_get_contents($legislator_menu_file);
$template = file_get_contents($template_file);

/*
* Swap out the placeholder with the menu contents
*/
$template = str_replace('<!--legislator_menu-->', $legislator_menu, $template);

if (file_put_contents($template_file, $template) == false)
{
echo 'Error: Failed in adding legislators listing to the menu.' . "\n";
exit(1);
}

echo 'Successfully inserted list of legislators into the site template.' . "\n";
5 changes: 4 additions & 1 deletion deploy/postdeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,8 @@ then

fi

# Expire the cached template (in case we've made changes to it)
# Populate the template with the list of legislators
php deploy/populate_menu.php

# Expire the cached template
echo "delete template-new" | nc -N localhost 11211 || true
10 changes: 5 additions & 5 deletions deploy/settings-docker.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
# As defined by the year.
define('SESSION_YEAR', 2019);

# Determine whether the GA is currently in session.
define('IN_SESSION', 'Y');
# Is the GA currently in session?
define('IN_SESSION', true);

# Is it a time of year when the legislature is doing anything at all?
define('LEGISLATIVE_SEASON', true);

# Set the FTP auth pair for legislative data.
define('LIS_FTP_USERNAME', '');
Expand Down Expand Up @@ -57,9 +60,6 @@
# Google Maps
define('GMAPS_KEY', '');

# Geoparser.io API key
define('GEOPARSER_KEY', '');

# Open States (Sunlight Foundation) API Key
define('OPENSTATES_KEY', '');

Expand Down
2 changes: 1 addition & 1 deletion htdocs/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
}

# Select the most popular bills of the past X days.
if (IN_SESSION == 'Y')
if (LEGISLATIVE_SEASON == true)
{
$days = 3;
}
Expand Down
Loading

0 comments on commit 381352d

Please sign in to comment.