Skip to content

Commit 5e3a591

Browse files
committed
handler: deploy swagger and update terraform
1 parent 041af52 commit 5e3a591

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

.circleci/config.yml

+30-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,38 @@ jobs:
3939
- run:
4040
name: Nix build
4141
command: |
42-
ls
43-
pwd
4442
./script/test
4543
44+
- run:
45+
name: "Update Node.js and npm"
46+
command: |
47+
nix-env -f ./nix -iA nodejs-10_x
48+
49+
- run:
50+
name: Install netlify-cli
51+
command: |
52+
npm install netlify-cli
53+
54+
- run: # TODO: shouldn't deploy to prod on every commit
55+
name: Netlify deploy
56+
command: |
57+
echo "Branch:" "$CIRCLE_BRANCH"
58+
echo "Repo:" "$CIRCLE_REPOSITORY_URL"
59+
echo "PR:" "$CIRCLE_PULL_REQUEST"
60+
if [ "$CIRCLE_BRANCH" == "master" ]; then
61+
echo "Deploying to production"
62+
./node_modules/netlify-cli/bin/run deploy \
63+
--dir=$(nix-build -A swaggerUi --no-link) \
64+
--message="$CIRCLE_SHA1" --prod
65+
elif [ -n "$CIRCLE_PULL_REQUEST" ]; then
66+
echo "One time deploy for PR $CIRCLE_PR_NUMBER"
67+
./node_modules/netlify-cli/bin/run deploy \
68+
--dir=$(nix-build -A swaggerUi --no-link) \
69+
--message="$CIRCLE_SHA1"
70+
else
71+
echo "Not deploying"
72+
fi
73+
4674
workflows:
4775
version: 2
4876
build:

infra/default.nix

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ rec
1616

1717
publicKey = builtins.readFile ./public.cer;
1818

19+
swaggerUi = pkgs.runCommand "swagger-ui" {}
20+
''
21+
mkdir -p $out
22+
${handler}/bin/swagger $out
23+
'';
24+
1925
googleResp = { "key1" = publicKey ; };
2026

2127
apiDir = pkgs.writeTextFile

infra/handler/app/Swagger.hs

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import qualified Network.Wai.Handler.Warp as Warp
1010
import qualified Servant as Servant
1111
import qualified Servant.Swagger as Servant
1212
import qualified Servant.Swagger.UI.Extended as Servant
13+
import System.Environment (getArgs)
1314

1415
type SwaggerAPI = Servant.SwaggerSchemaUI "swagger-ui" "swagger.json"
1516

1617
swaggerApi :: Proxy SwaggerAPI
1718
swaggerApi = Proxy
1819

1920
main :: IO ()
20-
main = serveSwagger
21+
main = do
22+
[dir] <- getArgs
23+
dumpSwagger dir
2124

2225
swagger :: Swagger.Swagger
2326
swagger = Servant.toSwagger (Proxy :: Proxy DeckGo.Handler.SlidesAPI)

infra/lambda.tf

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ data "aws_iam_policy_document" "policy_for_lambda" {
6060
]
6161

6262
resources = [
63-
"${aws_dynamodb_table.deckdeckgo-test-dynamodb-table.arn}",
63+
"${aws_dynamodb_table.deckdeckgo-test-dynamodb-table-decks.arn}",
6464
"${aws_dynamodb_table.deckdeckgo-test-dynamodb-table-slides.arn}",
65+
"${aws_dynamodb_table.deckdeckgo-test-dynamodb-table-users.arn}",
6566
]
6667
}
6768

0 commit comments

Comments
 (0)