Skip to content

Commit

Permalink
fixed Docker container (#353)
Browse files Browse the repository at this point in the history
* Update Dockerfile

- use node:lts-alpine so it stays up to date + slims down container size
- copy over package.json first so that container will only run npm install when deps change
- explicitly expose port
- run as node (aka not root)

* publish docker container to github registry

- all config from the default github action as of jun 10 2024

* set path to Dockerfile

* Update Dockerfile

* Update Dockerfile

revert slim install (forgot about separate client install)

* Update Dockerfile

* point Docker start command to dist folder

* Update Dockerfile

moved NODE_ENV to after build commands (build was failing with sh: webpack not found

* set api url to current host on prod

was defaulting to azure host in prod

* Update index.tsx

* doc pre-built Docker image in the docker readme
  • Loading branch information
nexus-uw authored Jun 12, 2024
1 parent 75aa45c commit b153788
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 11 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Docker

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

on:
schedule:
- cron: '43 11 * * *'
push:
branches: [ "master" ]
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "master" ]

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}


jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write

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

# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
with:
cosign-release: 'v2.2.4'

# Set up BuildKit Docker container builder to be able to build
# multi-platform images and export cache
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
with:
context: .
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
5 changes: 5 additions & 0 deletions client/src/pages/messaging/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ if(process.env.NODE_ENV === 'development') {
apiURL: 'http://localhost:3000',
socketURL: 'http://localhost:3000',
})
} else {
setConfig({
apiURL: `${window.location.protocol}//${window.location.hostname}` ,
socketURL: `${window.location.protocol}//${window.location.hostname}` ,
})
}

const chate2ee = createChatInstance();
Expand Down
20 changes: 11 additions & 9 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
FROM node:12.18.3-buster
FROM node:lts-alpine

#Set production mode deployment
ENV NODE_ENV "production"

#copy the content of current directory to /app inside container
COPY . /chat-e2ee
WORKDIR /chat-e2ee
# todo break apart client and server dep installs/builds so that they can be cached b/w builds
COPY . /chat-e2ee/

WORKDIR /chat-e2ee
RUN npm install

RUN npm install --unsafe-perm
RUN npm run build

RUN npm run build
# todo - multi part build (lets us slim down container to not unclude all the webpack stuff)

RUN rm .env.sample

EXPOSE 3001
USER node
#Set production mode deployment
ENV NODE_ENV "production"
ENTRYPOINT [ "npm", "run", "docker_start" ]
6 changes: 5 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ From the project root directory, issue the following command :
docker build . -f docker/Dockerfile -t chat-e2e:latest
```

##### Alternatively, there is a pre-built docker image

it is available at ```ghcr.io/muke1908/chat-e2ee:master```

##### Running the docker container

1. Create a .env file
Expand Down Expand Up @@ -61,4 +65,4 @@ Once the build completes, run the docker-compose file :
docker-compose up
```

You will see two services up and running. Now go to `localhost:3001` to use the app.
You will see two services up and running. Now go to `localhost:3001` to use the app.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test": "cross-env NODE_ENV=test jest",
"start": "cross-env NODE_ENV=production npm run serve",
"postinstall": "npm run build-service-sdk && cd client && npm install",
"docker_start": "cross-env NODE_ENV=production node index",
"docker_start": "cross-env NODE_ENV=production node ./dist/index",
"build-service-sdk": "cd service && npm install && npm run build",
"publish-sdk": "cd service && npm run publish-sdk"
},
Expand Down

0 comments on commit b153788

Please sign in to comment.