Skip to content

Commit f010263

Browse files
authored
Migrate DApp to Heroku (#1217)
* Try setting up heroku build * Add root package.json for buildpack detection * Update Dockerfile * Update Dockerfile * Use Node.js v16 * Build docker images using Github actions * Fix actions * Fix actions * Remove docker context * Fix deps * Fix push bug * Fix port * Fix port * Tweak image building step * Fix workflow * Deploy and push in Actions * Fix workflow * Cleanup * Remove unnecessary deps * Extract env before deploy * Fix env path * Fix path * Checkout and change context * Change Heroku app name * Remove references to local branch
1 parent f0a91e4 commit f010263

File tree

5 files changed

+88
-35
lines changed

5 files changed

+88
-35
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/ousd.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,65 @@ jobs:
146146
env:
147147
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
148148
with:
149-
args: --severity-threshold=high --all-projects
149+
args: --severity-threshold=high --all-projects
150+
151+
build-image:
152+
name: "Deploy App"
153+
runs-on: ubuntu-latest
154+
needs: [contracts-lint, dapp-lint]
155+
env:
156+
HEROKU_TOKEN: ${{ secrets.HEROKU_TOKEN }}
157+
CURR_BRANCH: ${{ github.ref_name }}
158+
if: ${{ contains(fromJSON('["master", "staging", "stable"]'), github.ref_name) }}
159+
steps:
160+
- uses: actions/checkout@v3
161+
162+
- name: Set up QEMU
163+
uses: docker/setup-qemu-action@v2
164+
165+
- name: Set up Docker Buildx
166+
uses: docker/setup-buildx-action@v2
167+
168+
- name: Run Docker Login
169+
run: docker login --username =_ --password=$HEROKU_TOKEN registry.heroku.com
170+
171+
- name: Identify Heroku App Name
172+
shell: bash
173+
run:
174+
if [[ $CURR_BRANCH == "stable" ]]; then
175+
echo "HEROKU_APP_NAME=ousd-dapp" >> $GITHUB_ENV;
176+
else
177+
echo "HEROKU_APP_NAME=ousd-dapp-staging" >> $GITHUB_ENV;
178+
fi;
179+
id: heroku_app
180+
181+
- name: Heroku Login
182+
uses: akhileshns/[email protected]
183+
if: ${{ contains(fromJSON('["staging", "stable"]'), github.ref_name) }}
184+
with:
185+
justlogin: true
186+
heroku_api_key: ${{secrets.HEROKU_TOKEN}}
187+
heroku_app_name: ${{env.HEROKU_APP_NAME}}
188+
heroku_email: ${{secrets.HEROKU_EMAIL}}
189+
190+
- name: Extract Deployment Env
191+
env:
192+
HEROKU_APP_NAME: ${{env.HEROKU_APP_NAME}}
193+
working-directory: dapp
194+
run: heroku config -s -a $HEROKU_APP_NAME > deploy.env
195+
- name: Build and Push
196+
uses: docker/build-push-action@v3
197+
if: ${{ contains(fromJSON('["staging", "stable"]'), github.ref_name) }}
198+
env:
199+
NODE_ENV: production
200+
with:
201+
context: .
202+
push: true
203+
tags: registry.heroku.com/${{env.HEROKU_APP_NAME}}/web
204+
provenance: false
205+
206+
- name: Deploy to Heroku
207+
if: ${{ contains(fromJSON('["staging", "stable"]'), github.ref_name) }}
208+
env:
209+
HEROKU_APP_NAME: ${{env.HEROKU_APP_NAME}}
210+
run: heroku container:release web -a $HEROKU_APP_NAME

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM node:16-alpine
2+
3+
# Install Git
4+
RUN apk update
5+
RUN apk add git
6+
7+
# Copy files over
8+
WORKDIR /app
9+
COPY contracts ./contracts
10+
COPY dapp ./dapp
11+
12+
# Build contract files
13+
WORKDIR /app/contracts
14+
RUN yarn install
15+
RUN yarn deploy
16+
17+
# Build DApp
18+
WORKDIR /app/dapp
19+
RUN yarn install
20+
RUN NODE_ENV=production yarn build
21+
22+
CMD ["yarn", "start"]

dapp/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"ipfs-export": "DEPLOY_MODE=ipfs yarn run build && next export",
1414
"start": "per-env",
1515
"start:development": "NODE_ENV=development ETHEREUM_RPC_PROVIDER=http://localhost:8545 next dev",
16-
"start:production": "NODE_ENV=production next start -p 8080",
16+
"start:production": "NODE_ENV=production next start -p $PORT",
1717
"gcp-build": "next build",
1818
"encrypt-secrets:prod": "gcloud kms encrypt --ciphertext-file=prod.secrets.enc --plaintext-file=prod.env --location=global --keyring=origin --key=cloudbuild",
1919
"decrypt-secrets:prod": "gcloud kms decrypt --ciphertext-file=prod.secrets.enc --plaintext-file=prod.env --location=global --keyring=origin --key=cloudbuild",

heroku.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build:
2+
docker:
3+
web: Dockerfile

0 commit comments

Comments
 (0)