Commit Graph

66 Commits

Author SHA1 Message Date
Leo Hemsted
46b0cce17b set startup timeout to 10 minutes
5 minutes isn't long enough to scale api at load, leading to failed deploys
2019-10-15 12:09:06 +01:00
Leo Hemsted
9e64dcbb2f clean up docker and makefile
* remove gosuuser - this means we can upgrade the base image to
  something more modern and not have to faff around with gpg
* remove unnecessary commands - some things need to exist in the
  makefile to keep jenkins happy
* remove concept of building separately - pip install requirements.txt
  in the dockerfile
2019-10-11 13:55:21 +01:00
Andy Paine
655d5a4e16 AUTO-413: Use an internal app for statsd preview
- We are running statsd exporter as an app with a public route for
  Prometheus to scrape
- This updates preview to send statsd metrics over the CF internal
  networking to the statsd exporter
- Removes the sidecar statsd exporters too
2019-05-23 11:10:33 +01:00
Leo Hemsted
652ccbb990 Can't use --no-start flag
--no-start doesn't actually stage, which we need to get the files containing the new migrations.
2019-05-16 16:20:15 +01:00
Leo Hemsted
9d415cd292 remove unnecessary unique index
primary key provides the same control. also catch the right exception
in the related command
2019-05-16 14:36:17 +01:00
Leo Hemsted
05c9144a89 update manifest file to use zdt-push
this way we keep db bindings etc, and avoid accidentally dropping
connections.
2019-05-16 10:52:54 +01:00
Leo Hemsted
7a711cf314 Revert "Zero downtime deploy" 2019-05-15 13:48:40 +01:00
Leo Hemsted
b2f87378c3 update manifest file to use zdt-push
this way we keep db bindings etc, and avoid accidentally dropping
connections.
2019-05-09 14:37:47 +01:00
Athanasios Voutsadakis
bf4e75da40 Explicitly target the right space before deploying 2019-04-24 15:55:45 +01:00
Alexey Bezhan
dc904f8742 Add a make target to download statsd_exporter binary
Downloads a linux binary from Github and puts it in the scripts folder.
This should add it to the package CI uploads to CF during deploy.

Unfortunately, since out .cfignore is a symlink to .gitignore we
can't add the file to be ignored by git, so it shows up in untracked
if `cf-deploy` is run locally.
2019-04-24 11:25:38 +01:00
Leo Hemsted
8cc5d40291 remove old manifest files and creation script 2019-04-10 15:21:30 +01:00
Leo Hemsted
66ca98fbfb create manifest from jinja template
newer versions of cf api don't allow you to have multiple apps per
manifest file. So, instead of our current inheritance based model, move
to the newer doc-dl/antivirus/template-preview approved jinja based
model.

the new single manifest.yml.j2 file sets a bunch of variables based on
the CF_APP variable - things like NOTIFY_APP_NAME, default instances,
etc. Then the manifest is built up to define all of the app options
based on these defaults. Things default to sensible values, which can
vary based on environment.

When adding new environment variables, you'll need to add them to the
manifest file. If they're json encoded lists, you'll need to pass them
back to the `tojson` filter, or jinja2 will print them as python lists,
with single quotes around strings.
2019-04-10 15:15:48 +01:00
Leo Hemsted
2ed50e760f Revert "Celery 4" 2018-10-09 13:27:49 +01:00
Leo Hemsted
bfc4343b0e remove pip-accel and make sure commands work if you're in a venv
remove pip-accel - it's not been updated in two years, and pins our
version of pip to a version that is several breaking changes old.

make sure commands work if you're already in a venv - mostly by
checking for presence of $VIRTUAL_ENV, and ensuring we use the correct
pip to install packages. Also clean up the commands a bit.
2018-10-04 15:52:51 +01:00
Leo Hemsted
640f00b0e8 install celery with sqs support
you need to `pip install celery[sqs]` to get the additional
dependencies that celery needs to use SQS queues - there are two libs -
boto3 and pycurl.

pycurl is a bunch of python handles around curl, so needs to be
installed from source so it can link to your curl/ssl libs. On paas and
in docker this works fine (needed to add `libcurl4-openssl-dev` to the
docker container), but on macos it can't find openssl. We need to pass
a couple of flags in:

* set the environment variable PYCURL_SSL_LIBRARY=openssl
* pass in the global options `build_ext` and `-I{openssl_headers_path}`.

As shown here:
https://github.com/pycurl/pycurl/issues/530#issuecomment-395403253

Env var is no biggie, but using any install-option flags disables
wheels for the whole pip install run. (See
https://github.com/pypa/pip/issues/2677 and
https://github.com/pypa/pip/issues/4118 for more context on the
install-options flags). A whole bunch of our dependencies don't
install nicely from source (but do from wheel), so this commit installs
pycurl separately as an initial step, with the requisite flags, and
then installs the rest of the requirements as before.

I've updated the makefile and bootstrap.sh files to reflect this, but
if you run `pip install -r requirements.txt` from scratch you will run
into issues.
2018-10-03 14:11:30 +01:00
Alexey Bezhan
ce5bb1f762 Make pyup ignore requirements.txt
We don't want pyup.io upgrading sub-dependencies listed in the
requirements.txt file since it does it whenever a new version is
available regardless of what our application dependencies require.
2018-07-30 16:26:10 +01:00
Alexey Bezhan
75940c9566 Pin all application requirements in requirements.txt
The list of top-level dependencies is moved to requirements-app.txt,
which is used by `make freeze-requirements` to generate the full
list of requirements in requirements.txt.

This is based on alphagov/digitalmarketplace-api#615, so rationale
from that PR applies here.

We had a problem with unpinned packages on new deployments leading
to failed tests (e.g. alphagov/notifications-admin#2144) which is
why we're implementing this now.

After re-evaluating pipenv again, this still seems like the least
disruptive approach:

* pyup.io has experimental support for Pipfile, but doesn't respect
  version ranges or updating hashes in the lock file
* CloudFoundry buildpack recognizes and supports Pipfiles out of the
  box, but the support is relatively new. For example until recently
  CF would install dev packages during deployment. It's also based on
  generating a requirements file from the Pipfile, which doesn't
  properly support pinning VCS dependencies (eg it doesn't set the
  #egg= version, meaning pip will not upgrade the package if it's
  already installed).
* pipenv has a strict dependency resolution algorithm, which doesn't
  appear to be well documented and can cause some unexpected failures.
  For example, pipenv doesn't seem to be able to install `awscli-cwlogs`
  package at all, believing it to have a version conflict for `botocore`
  (which it doesn't list as a direct dependency) while neither `pip` nor
  `pip-tools` highlight any issues with it.
* While trying out `pipenv install` on our list of dependencies it would
  regularly fail to install utils with a "Will try again." message.
  While the installation succeeds after a retry, this doesn't inspire
  confidence.
* The switch to Pipfile and pipenv-managed virtualenvs requires a series
  of changes to `make` targets and scripts - replacing `pip install` with
  `pipenv`, removing references to requirements files and prefixing
  commands with `pipenv run`. While it's likely to simplify the overall
  process of managing dependencies, it would require time to properly
  implement across our applications and environments (Jenkins, PaaS,
  docker containers, and dev machines).
2018-07-10 14:59:04 +01:00
Chris Hill-Scott
d36b742e14 Automatically set environment vars before tests
Sometimes you just wanna run some tests directly using the `pytest`
command. But you’re in a new shell, and have forgotten to do
`source environment_test.sh`. The screen fills with red, and your day
just got a little bit worse.

This commit will stop this from ever happening again, by making the
setting environment variables part of running Pytest. It does this with
a plugin called pytest-env[1].

pytest.ini is the standard way of configuring pytest. Creating this file
where it didn’t exist before changes the behaviour of pytest, in that
it will now look for tests in the same directory as the file, rather
than defaulting to the `tests/` directory. So we also have to explicitly
configure pytest[2] to tell it that it should only look in this
directory. Otherwise it gets lost in the weeds of `node_modules`.

This also changes the way that `SQLALCHEMY_DATABASE_URI` is overriden to
the convention used by this plugin.

1. https://github.com/MobileDynasty/pytest-env
2. https://docs.pytest.org/en/latest/customize.html#confval-testpaths

fixup! Remove environment_test.sh
2018-02-14 12:19:12 +00:00
Alexey Bezhan
466166c8fb Fix a typo in api-db-migration deployment make task 2018-01-09 11:45:01 +00:00
Alexey Bezhan
f2e6018512 Use generated manifest when deploying apps to PaaS
Adds a new `make generate-manifest` target which is called by
deployment steps.
2018-01-09 10:45:03 +00:00
Athanasios Voutsadakis
806e880ec2 Fix .PHONY reference 2017-12-28 18:29:31 +00:00
Athanasios Voutsadakis
e06b15aa3b Remove unused cf-build and cf-build-with-docker
We are using the non-cf versions of these commands
2017-12-28 18:28:51 +00:00
Athanasios Voutsadakis
4cc8bfb174 Remove unused DNS_NAME variable 2017-12-28 18:28:02 +00:00
Athanasios Voutsadakis
d487d57509 Remove targets related to AWS deployments
Also remove checks for unused variables
2017-12-28 18:24:36 +00:00
Athanasios Voutsadakis
2b829e1f17 Remove upload-codedeploy-artifact target 2017-12-28 18:21:39 +00:00
Athanasios Voutsadakis
a833bbf6d5 Remove build-codedeploy-artifact target
Also remove appspec files that are not used in the paas world.
2017-12-28 18:18:32 +00:00
Leo Hemsted
7d1c4ea722 fix makefile syntax 2017-12-14 15:16:43 +00:00
Leo Hemsted
c6e6fad01f if apps crash on startup, then fail deploy process
we saw an issue where the app started, then immediately crashed due to
a setup error. However, jenkins had already returned positively, and
the deploy continued.

cf-deploy should fail if the app doesn't start up.

We do this by looking through the cloudfoundry events, and aborting
if there are any `app.crash` events for the new GUID.
2017-12-14 14:23:32 +00:00
Leo Hemsted
bcee95214e Add sleep after stopping the old app instances on deploy
sleep for 10 seconds to try and make sure that all worker threads
(either web api or celery) have finished before we delete when we
delete the DB is unbound from the app, which can cause
"permission denied for relation" psycopg2 errors.
2017-11-27 13:46:39 +00:00
Leo Hemsted
4d75f032c6 remove cf stop to try and improve deploy robustness
Rationale:
Sometimes, when deploying, we've seen errors while stopping the old
apps: "(psycopg2.ProgrammingError) permission denied for relation notifications".

When you call cf stop, it may not be entirely synchronous. Under the
hood, cloudfoundry has to do a whole bunch of things when you stop an
app - it has its own internal db of what app states are, and also has
to remove it from any load balancers etc, and also it has to actually
stop the app. We're not sure if the `cf stop` command guarantees that
your process has already terminated by the time that the command
returns.

In our Makefile, we call `cf stop`, followed by `cf delete`. One
posisble theory is that the process is still running when `cf stop`
exits, and then `cf delete` unbinds that service from the database,
removing all of it's users' permissions.

This isn't confirmed, however, this commit removes the `cf stop`
command to see if it solves the issue. PaaS team confirmed that
it's redundant - `cf delete` will carry out the same tasks under
the hood.
2017-11-24 10:53:16 +00:00
Leo Hemsted
d30a8b83c1 update readme and ensure makefile up to date 2017-11-23 17:04:58 +00:00
Athanasios Voutsadakis
2e65417dc2 Explicitly target environment on cf-push 2017-10-31 16:51:49 +00:00
Athanasios Voutsadakis
2c590acff5 Also unbind notify-config and notify-aws 2017-10-02 16:25:49 +01:00
Athanasios Voutsadakis
912728713a Unbind the db service before pushing the app
This should cause the app to get new credentials for the database upon
pushing.
2017-09-27 12:11:44 +01:00
Imdad Ahad
6da3d3ed0b Remove wheels-ing on deployment 2017-07-21 14:26:59 +01:00
Imdad Ahad
726371269a Use python3 on jenkins otherwise SSL erorr occurs 2017-05-31 15:38:57 +01:00
Imdad Ahad
a58e724d21 Add a script and make command to detect if there are any migration changes 2017-05-26 16:44:23 +01:00
bandesz
92c95fe66a Run the db migration script without the run_app_paas.sh script, because it is not failing if the migration script fails 2017-03-23 17:45:16 +00:00
bandesz
c032ea5eee PaaS rollback: check if the rollback app is in a started state 2017-03-16 12:33:10 +00:00
bandesz
1e83f7d8e2 Remove Docker commands for CF, clean up artifact creation 2017-02-28 12:32:01 +00:00
bandesz
34f1eff84d Remove Jenkinsfiles, add PaaS build/upload artifact tasks 2017-02-28 10:47:11 +00:00
bandesz
e3cb908c1a Remove explicit api_host_name vars from the envs 2017-02-23 11:22:58 +00:00
imdadahad
978d99f708 Merge pull request #836 from alphagov/fix-remove-old-wheelhouse-contents
Delete old wheels on build
2017-02-20 16:01:56 +00:00
bandesz
9082aeffa3 Make Docker container names unique for PaaS deployment 2017-02-20 13:21:40 +00:00
Imdad Ahad
28944e3952 Delete old wheels on build 2017-02-20 13:09:30 +00:00
Imdad Ahad
952110577f Remove target dir before build and include any dotfiles in the zips 2017-02-20 10:09:59 +00:00
bandesz
72dc93c6db Add awslogs logging for PaaS 2017-02-16 17:38:30 +00:00
Andras Ferencz-Szabo
e10c5e28cd Merge pull request #763 from alphagov/cloudfoundry
Run on Paas
2017-01-17 11:28:38 +00:00
bandesz
e9a90b46b0 Add Makefile commands to control autoscaling processes 2017-01-16 17:53:11 +00:00
bandesz
ac0e1f1def Add gosu and host user to Docker 2017-01-13 10:24:13 +00:00