Skip to content

Commit

Permalink
add docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jun 1, 2024
1 parent 53d0b12 commit 73d5021
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Build Docker Image

on:
push:
branches:
- 'main'
workflow_dispatch:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- id: prep
name: find version
shell: bash
run: |
version=$(jq -r '.version' package.json)
echo "Found version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GHCR (GitHub Packages)
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
with:
push: true
tags: |
ghcr.io/${{github.repository}}:latest
ghcr.io/${{github.repository}}:${{steps.prep.outputs.version}}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20-alpine

RUN apk add --no-cache bash tini

EXPOSE 3000

ENV CRANLIKE_MONGODB_SERVER="mongo" \
VCAP_APP_HOST="0.0.0.0"

COPY . /frontend

WORKDIR /frontend

RUN npm install .

ENTRYPOINT [ "tini", "--", "/frontend/entrypoint.sh"]
22 changes: 22 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set -eo pipefail

function wait_tcp_port {
local host="$1" port="$2"
local max_tries=5 tries=1

# see http://tldp.org/LDP/abs/html/devref1.html for description of this syntax.
while ! exec 6<>/dev/tcp/$host/$port && [[ $tries -lt $max_tries ]]; do
sleep 1s
tries=$(( tries + 1 ))
echo "$(date) retrying to connect to $host:$port ($tries/$max_tries)"
done
exec 6>&-
}

# wait for the mongo server to be available
echo Waiting for ${CRANLIKE_MONGODB_SERVER}:${CRANLIKE_MONGODB_PORT:-27017}...
wait_tcp_port "${CRANLIKE_MONGODB_SERVER}" "${CRANLIKE_MONGODB_PORT:-27017}"

# run mongo-express
exec npm start
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "express-frontend",
"version": "0.0.0",
"private": true,
"version": "1.0.0",
"scripts": {
"start": "node ./bin/www"
},
Expand Down

0 comments on commit 73d5021

Please sign in to comment.