Skip to content

Commit 7a7a100

Browse files
authored
Merge pull request #5151 from nulib/deploy/staging
Deploy v10.3.0 to production
2 parents 3356f4d + d915d5f commit 7a7a100

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+13717
-3820
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ jobs:
4343
MIX_ENV: test
4444
steps:
4545
- uses: actions/checkout@v2
46-
- name: Start service containers in background
47-
run: docker compose up -d &
48-
working-directory: ./infrastructure/localstack
4946
- uses: actions/setup-node@v3
5047
with:
5148
node-version-file: ./.tool-versions
@@ -54,27 +51,13 @@ jobs:
5451
app/assets/package-lock.json
5552
app/priv/nodejs/*/package-lock.json
5653
lambdas/*/package-lock.json
54+
- name: Start service containers in background
55+
run: make localstack-start &
5756
- uses: erlef/setup-beam@v1
5857
with:
59-
otp-version: "27"
60-
elixir-version: "1.18.2"
58+
version-file: ./.tool-versions
59+
version-type: strict
6160
- uses: hashicorp/setup-terraform@v3
62-
- name: Install FFMPEG
63-
run: |
64-
mkdir -p ${{ runner.temp }}/ffmpeg && \
65-
cd ${{ runner.temp }}/ffmpeg && \
66-
curl https://s3.amazonaws.com/nul-repo-deploy/ffmpeg-release-64bit-static.tar.xz | tar xJ && \
67-
sudo cp $(find . -type f -executable) /usr/local/bin/ && \
68-
echo "FFMPEG VERSION: $(ffmpeg -version | sed -n "s/ffmpeg version \([-0-9.]*\).*/\1/p;")"
69-
- name: Install ExifTool
70-
run: |
71-
EXIFTOOL_VERSION=$(curl -s https://exiftool.org/ver.txt)
72-
mkdir -p ${{ runner.temp }}/exiftool && \
73-
cd ${{ runner.temp }}/exiftool && \
74-
curl -L -s https://exiftool.org/Image-ExifTool-${EXIFTOOL_VERSION}.tar.gz | tar xz && \
75-
cd Image-ExifTool-${EXIFTOOL_VERSION} && \
76-
perl Makefile.PL && \
77-
sudo make install
7861
- name: Cache Elixir dependencies and build
7962
uses: actions/cache@v4
8063
with:
@@ -90,33 +73,23 @@ jobs:
9073
working-directory: app
9174
env:
9275
MIX_ENV: test
93-
- name: Install Lambda dependencies
94-
run: |
95-
for pkg in $(find app/priv/nodejs -maxdepth 2 -name package-lock.json) $(find lambdas -maxdepth 2 -name package-lock.json)
96-
do
97-
cd $(dirname $pkg)
98-
npm ci --no-fund
99-
cd -
100-
done
101-
- name: Wait for services to be ready
102-
run: timeout 60 bash -c 'while ! ./all-healthy.sh; do sleep 2; done'
103-
working-directory: ./infrastructure/localstack
104-
- name: Set SECRET_KEY_BASE
105-
run: echo "SECRET_KEY_BASE=$(openssl rand -hex 32)" >> $GITHUB_ENV
106-
- name: Provision Localstack using Terraform
107-
run: |
108-
terraform init
109-
terraform apply -auto-approve -var-file test.tfvars -var localstack_endpoint=https://localhost.localstack.cloud:4566
110-
working-directory: ./infrastructure/localstack
11176
- name: Install Claude Code
11277
run: npm install -g @anthropic-ai/claude-code
11378
- name: Elixir Static Analysis
11479
run: mix credo
11580
working-directory: app
81+
- name: Wait for services to be ready
82+
run: timeout 120 bash -c 'while ! ./all-healthy.sh; do sleep 2; done'
83+
working-directory: ./infrastructure/localstack
84+
- name: Set SECRET_KEY_BASE
85+
run: echo "SECRET_KEY_BASE=$(openssl rand -hex 32)" >> $GITHUB_ENV
86+
- name: Provision Localstack using Terraform
87+
run: make localstack-provision
11688
- name: Elixir Tests
11789
run: mix test || mix test --seed $(cat ${MEADOW_TEST_SAVE_SEED}) --failed
11890
env:
11991
AWS_LOCALSTACK: true
92+
USE_SAM_LAMBDAS: true
12093
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
12194
MEADOW_TEST_SAVE_SEED: ${{ runner.temp }}/MEADOW_TEST_SEED
12295
working-directory: app

.gitignore

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ npm-debug.log
4444
/app/priv/cert/
4545
/app/priv/seed_data/
4646

47+
/lambdas/**/*.log
48+
4749
.elixir_ls
4850

4951
*.tfvars
5052

53+
/infrastructure/**/.aws-sam
5154
/infrastructure/**/.terraform/
5255
/infrastructure/**/*.tfstate*
5356
/infrastructure/**/_build/
54-
/infrastructure/**/build/
57+
/infrastructure/**/build/*
58+
!/infrastructure/pipeline/layers/build/*
5559
/infrastructure/**/builds/
5660
/infrastructure/**/package/
5761
/infrastructure/**/*.plan
62+
/infrastructure/pipeline/layers/*.zip
5863

5964
/app/tmp/
6065

@@ -71,6 +76,8 @@ yarn.lock
7176
.DS_Store
7277
**/*/.DS_Store
7378

79+
**/*.pid
80+
7481
lambdas/stream-authorizer/config
7582
.env
7683
AGENT.md
@@ -82,4 +89,7 @@ AGENT.md
8289
/app/priv/python/agent/**/__pycache__/
8390
/app/priv/python/agent/**/*.pyc
8491
/app/priv/python/agent/**/*.pyo
85-
/app/priv/python/agent/**/*.pyd
92+
/app/priv/python/agent/**/*.pyd
93+
94+
.aws-sam/
95+
samconfig.*

.tool-versions

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
nodejs 22.14.0
2-
erlang 27.3
3-
elixir 1.18.2-otp-27
4-
terraform 1.7.4
5-
tflint 0.34.1
1+
nodejs 22.14.0
2+
erlang 27.3
3+
elixir 1.18.2-otp-27
4+
terraform 1.7.4
5+
aws-sam-cli 1.152.0
66
#npm 11.6.0

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ifndef VERBOSE
2+
.SILENT:
3+
endif
4+
5+
MAKEFLAGS += --no-print-directory
6+
SHELL := /bin/bash
7+
LOCALSTACK_DIR ?= ./infrastructure/localstack
8+
PIPELINE_DIR ?= ./infrastructure/pipeline
9+
TERRAFORM_DIR ?= ./infrastructure/deploy
10+
11+
.PHONY: help
12+
13+
help:
14+
@make localstack-help | sed 's/^make /make localstack-/'
15+
@make pipeline-help | sed 's/^make /make pipeline-/'
16+
17+
localstack-%:
18+
cd $(LOCALSTACK_DIR) && make $*
19+
20+
pipeline-%:
21+
cd $(PIPELINE_DIR) && make $*
22+
23+
api-%:
24+
cd ../dc-api-v2 && make $*

README.md

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
- Run `mix meadow.setup`. This creates the Sequins pipeline, S3 buckets, and database.
1616
- Install Node.js dependencies with `mix assets.install`
1717
- `assets.install` looks for all `package-lock.json` files project-wide and runs `npm install` in each directory found, so you don't need to run `npm install` in individual directories.
18-
- run `sg open all 3001`
18+
- run `sgport open all 3001`
1919
- Start the Phoenix server with `mix phx.server` (or `iex -S mix phx.server` if you want to an interactive shell).
2020

2121
Now you can visit [`https://[YOURENV].dev.rdc.library.northwestern.edu:3001/`](https://[YOURENV].dev.rdc.library.northwestern.edu:3001/) from your browser.
@@ -28,13 +28,14 @@ You can stop the Phoenix server with `Ctrl + C` twice
2828

2929
If you need to clear your data and reset the entire development environment, from `meadow/app` run:
3030

31-
```
31+
```bash
3232
mix ecto.reset
3333
mix meadow.search.clear
3434
mix meadow.pipeline.purge
3535
clean-s3 dev -y
36-
36+
```
3737
...then
38+
```bash
3839
mix deps.get
3940
mix meadow.setup
4041
mix phx.server
@@ -56,36 +57,30 @@ If you would like to interact directly with the database
5657

5758
### Run the Elixir test suite
5859

59-
#### Start Test Services
60+
#### Start/Provision Test Environment
6061

6162
In one terminal:
63+
```bash
64+
make localstack-provision
6265
```
63-
cd infrastructure/localstack
64-
docker compose up
65-
```
66-
67-
#### Provision Test Environment
68-
69-
Watch the logs until the services seem to stabilize. Then, in another terminal:
70-
```
71-
cd infrastructure/localstack
72-
terraform init
73-
terraform apply -auto-approve \
74-
-var-file test.tfvars \
75-
-var localstack_endpoint=https://localhost.localstack.cloud:4566
76-
```
77-
78-
You will probably see `Warning: AWS account ID not found for provider`, but this can be safely ignored.
7966

8067
#### Run Tests
8168

82-
```
69+
```bash
8370
cd app
84-
export AWS_LOCALSTACK=true
71+
export AWS_LOCALSTACK=true
8572
mix test [test args...]
8673
```
8774

88-
**Note:** `mix test` can be run repeatedly without re-provisioning as long as the Docker services are running. If you stop the services, you will need to run Terraform again. Also, do not try to run Meadow with `export AWS_LOCALSTACK=true` set.
75+
**Note:** Do not try to run Meadow with `export AWS_LOCALSTACK=true` set.
76+
77+
#### Stop/Deprovision Test Environment
78+
79+
Back in the meadow root directory:
80+
81+
```bash
82+
make localstack-stop
83+
```
8984

9085
### GraphQL API
9186

@@ -113,13 +108,13 @@ To force an Elasticsearch re-index, and not wait for the 2-minute cycle to kick
113108

114109
Run the interactive shell in a terminal tab
115110

116-
```
111+
```bash
117112
iex -S mix
118113
```
119114

120115
And force a re-index:
121116

122-
```
117+
```elixir
123118
Meadow.Data.Indexer.reindex_all()
124119
```
125120

@@ -254,18 +249,28 @@ change_b = Enum.at(changes, 1)
254249

255250
### Doing development on the Meadow Pipeline lambdas
256251

257-
In the AWS developer environment, the lambdas associated with the pipeline are shared amongst developers. In order to do development and see whether it's working you can override the configuration to use your local files instead of the deployed lambdas. Example below (you don't have to override them all. Just the ones you need).
252+
In the AWS developer environment, the lambdas associated with the pipeline are shared amongst developers. In order to do development and see whether it's working you can override the configuration to use the SAM pipeline the deployed lambdas.
258253

259-
Edit `config/dev.local.exs` to get the lambdas to use the local copy through the port:`
254+
In one terminal:
255+
```bash
256+
make pipeline-start
257+
```
260258

261-
```elixir
262-
config :meadow, :lambda,
263-
digester: {:local, {Path.expand("../lambdas/digester/index.js"), "handler"}},
264-
exif: {:local, {Path.expand("../lambdas/exif/index.js"), "handler"}},
265-
frame_extractor: {:local, {Path.expand("../lambdas/frame-extractor/index.js"), "handler"}},
266-
mediainfo: {:local, {Path.expand("../lambdas/mediainfo/index.js"), "handler"}},
267-
mime_type: {:local, {Path.expand("../lambdas/mime-type/index.js"), "handler"}},
268-
tiff: {:local, {Path.expand("../lambdas/pyramid-tiff/index.js"), "handler"}}
259+
In another terminal:
260+
```bash
261+
cd app
262+
USE_SAM_LAMBDAS=true iex -S mix phx.server
263+
```
264+
265+
266+
#### Deploying lambdas with SAM
267+
268+
The pipeline infrastructure is defined in `infrastructure/pipeline/template.yaml` and can be deployed with
269+
the AWS SAM CLI. There are `make` tasks to assist. Make sure `AWS_PROFILE` is set to the correct admin
270+
profile and logged in, and then:
271+
272+
```bash
273+
make pipeline-deploy ENV=staging
269274
```
270275

271276
### TypeScript/GraphQL Types

app/Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ RUN npm ci --force
3131
COPY ./priv/nodejs /app/priv/nodejs
3232
WORKDIR /app/priv/nodejs
3333
RUN for flag in $(find . -name .docker-npm); do \
34-
cd $(dirname ${flag}); \
35-
npm ci; \
36-
cd -; \
34+
(cd $(dirname ${flag}) && npm ci); \
3735
done
3836
WORKDIR /app
3937
ARG HONEYBADGER_API_KEY=

0 commit comments

Comments
 (0)