Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
ci: multistage container build
Browse files Browse the repository at this point in the history
We've been hosting the dapp as a static website, but the developers have
maintained it as a single-page application (SPA). Let's update the
containerfile to handle hosting the app so we can deploy via container
image.
  • Loading branch information
conorsch committed Jun 12, 2023
1 parent d466191 commit 1f44296
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 15 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Build container image
on:
workflow_call:
workflow_dispatch:
push:
branches:
- main
tags:
- '**'
jobs:
build-and-push-penumbra:
runs-on: buildjet-16vcpu-ubuntu-2004
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Docker Hub container registry (for pulls)
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Log in to the GitHub container registry (for pushes)
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/penumbra-zone/dapp

- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
17 changes: 7 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
FROM node:16

ENV PORT 9012
FROM node:16 AS builder

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY package*.json /usr/src/app/
RUN npm config set @buf:registry https://buf.build/gen/npm/v1/
RUN npm install

COPY . /usr/src/app
RUN npm run build

# Install a static webserver, to emulate Firebase static website hosting.
RUN npm install http-server -g
WORKDIR /usr/src/app/build
EXPOSE 9012
# CMD [ "npm", "start" ]
CMD [ "http-server" ]
EXPOSE 8080

# Not using a custom "prod" script from package.json,
# due to routing problems.
# CMD [ "npm", "run", "start:prod" ]
CMD [ "npm", "start" ]
5 changes: 3 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build:
./build-static-site
container:
docker build -t penumbra_dapp .
docker run -p 9012:9012 -it penumbra_dapp
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"web-vitals": "^2.1.0"
},
"scripts": {
"build": "webpack --config webpack.production.js",
"build": "webpack --config webpack.development.js",
"build:prod": "webpack --config webpack.production.js",
"start": "webpack-dev-server --progress --config webpack.development.js",
"start:prod": "webpack-dev-server --progress --config webpack.production.js",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage"
Expand Down
12 changes: 11 additions & 1 deletion webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ module.exports = {
patterns: [{ from: 'src/icons' }],
}),
],
devServer: {
client: {
logging: 'info',
overlay: false,
},
historyApiFallback: true,
compress: true,
static: './build',
port: 9012,
},
module: {
rules: [
{
Expand Down Expand Up @@ -48,4 +58,4 @@ module.exports = {
experiments: {
asyncWebAssembly: true,
},
};
};
3 changes: 2 additions & 1 deletion webpack.production.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ const common = require('./webpack.common.js');

module.exports = merge(common, {
mode: 'production',
});
stats: 'errors-only',
});

0 comments on commit 1f44296

Please sign in to comment.