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

Commit

Permalink
Merge pull request #61 from derogab/last-v1
Browse files Browse the repository at this point in the history
Last v1
  • Loading branch information
derogab authored Aug 10, 2021
2 parents 7c283d7 + 65e9907 commit ab581b0
Show file tree
Hide file tree
Showing 15 changed files with 41,092 additions and 12,842 deletions.
165 changes: 105 additions & 60 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
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:
push:
# Publish `master` as Docker `latest` image.
# Publish `master` and `dev` image.
branches:
- master
- dev

# Publish `v1.2.3` tags as releases.
tags:
Expand All @@ -14,13 +20,16 @@ on:
pull_request:

env:
# TODO: Change variable to your image's name.
IMAGE_NAME_CLIENT: coingraph-client
IMAGE_NAME_DAEMON: coingraph-daemon
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME_DAEMON: ${{ github.repository }}-daemon
IMAGE_NAME_CLIENT: ${{ github.repository }}-client


jobs:

# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

Expand All @@ -33,70 +42,106 @@ jobs:
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build ./daemon/ --file Dockerfile
docker build . --file Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Push daemon image to GitHub Packages.
push-daemon:

# Ensure test job passes before pushing image.
needs: test

runs-on: ubuntu-latest
if: github.event_name == 'push'
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v2

- name: Build client image
run: docker build . --tag $IMAGE_NAME_CLIENT

- name: Build daemon image
run: docker build ./daemon --tag $IMAGE_NAME_DAEMON

- name: Log into registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin

- name: Push client image
run: |
IMAGE_ID_CLIENT=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME_CLIENT
# Change all uppercase to lowercase
IMAGE_ID_CLIENT=$(echo $IMAGE_ID_CLIENT | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

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

# 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@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
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: metad
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_DAEMON }}

# 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
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: ./daemon/
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metad.outputs.tags }}
labels: ${{ steps.metad.outputs.labels }}

# Push client image to GitHub Packages.
push-client:

# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID_CLIENT=$IMAGE_ID_CLIENT
echo VERSION=$VERSION
docker tag $IMAGE_NAME_CLIENT $IMAGE_ID_CLIENT:$VERSION
docker push $IMAGE_ID_CLIENT:$VERSION
- name: Push daemon image
run: |
IMAGE_ID_DAEMON=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME_DAEMON
# Change all uppercase to lowercase
IMAGE_ID_DAEMON=$(echo $IMAGE_ID_DAEMON | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
# Ensure test job passes before pushing image.
needs: test

echo IMAGE_ID_DAEMON=$IMAGE_ID_DAEMON
echo VERSION=$VERSION
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

docker tag $IMAGE_NAME_DAEMON $IMAGE_ID_DAEMON:$VERSION
docker push $IMAGE_ID_DAEMON:$VERSION
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v1

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

# 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@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
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: metac
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_CLIENT }}

# 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
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
platforms: linux/amd64,linux/arm64,linux/arm/v7
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.metac.outputs.tags }}
labels: ${{ steps.metac.outputs.labels }}
24 changes: 9 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
# build environment
FROM node:10 as build
FROM node:14

# Create app directory
WORKDIR /usr/src/app
# Set environments
ENV PATH /usr/src/app/node_modules/.bin:$PATH

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package.json ./
COPY yarn.lock ./
RUN yarn
COPY package*.json ./
RUN npm install

# Copy app
COPY . .
# Build
RUN yarn run build

# production environment
FROM nginx:stable-alpine
# Copy app
COPY --from=build /usr/src/app/build /usr/share/nginx/html
# Expose ports
EXPOSE 80
EXPOSE 3000

# Run command
CMD ["nginx", "-g", "daemon off;"]
CMD [ "npm", "start" ]
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Coingraph is a **real-time graph for cryptocurrencies**.

## Dependencies
```shell
yarn
npm install
```
And don't forget to also install the [daemon dependencies](./daemon/README.md#dependencies)!

Expand All @@ -22,15 +22,13 @@ If necessary, view the [daemon configurations](./daemon/README.md#configuration)

## Usage
```shell
yarn run all
npm run all
```
The previous command starts both the [daemon](./daemon) and the web interface.

## Docker

[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/derogab/coingraph?include_prereleases&style=flat-square)](https://github.com/derogab/coingraph/releases)
[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/derogab/coingraph-client/latest?style=flat-square)](https://hub.docker.com/r/derogab/coingraph-client)
[![Docker Pulls](https://img.shields.io/docker/pulls/derogab/coingraph-client?style=flat-square)](https://hub.docker.com/r/derogab/coingraph-client)

#### Manual
1. [Start the `coingraph-daemon`](./daemon/README.md#start-container) and then
Expand All @@ -39,7 +37,7 @@ The previous command starts both the [daemon](./daemon) and the web interface.
docker run -d \
-p 3000:3000 \
--link DAEMON_CONTAINER_ID \
derogab/coingraph-client
ghcr.io/derogab/coingraph-client
```

#### Using `docker-compose`
Expand Down
7 changes: 3 additions & 4 deletions daemon/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM node:10
FROM node:14

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package.json ./
COPY yarn.lock ./
RUN yarn
COPY package*.json ./
RUN npm install

# Copy app
COPY . .
Expand Down
10 changes: 4 additions & 6 deletions daemon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A daemon for coingraph who takes care of

## Dependencies
```shell
yarn
npm install
```

## Configuration
Expand All @@ -32,28 +32,26 @@ Info: custom params overwrite default preferences in `.env`.
## Docker

[![GitHub release (latest SemVer including pre-releases)](https://img.shields.io/github/v/release/derogab/coingraph?include_prereleases&style=flat-square)](https://github.com/derogab/coingraph/releases)
[![Docker Image Size (tag)](https://img.shields.io/docker/image-size/derogab/coingraph-daemon/latest?style=flat-square)](https://hub.docker.com/r/derogab/coingraph-daemon)
[![Docker Pulls](https://img.shields.io/docker/pulls/derogab/coingraph-daemon?style=flat-square)](https://hub.docker.com/r/derogab/coingraph-daemon)

###### Build image from source
```shell
docker build -t derogab/coingraph-daemon .
docker build -t ghcr.io/derogab/coingraph-daemon .
```
###### Start container
```shell
docker run -d \
-p 8080:8080 \
-p 8081:8081 \
-v /path/to/host/data:/usr/src/app/data \
derogab/coingraph-daemon
ghcr.io/derogab/coingraph-daemon
```
Or with custom params
```shell
docker run -d \
-p 8080:8080 \
-p 8081:8081 \
-v /path/to/host/data:/usr/src/app/data \
derogab/coingraph-daemon \
ghcr.io/derogab/coingraph-daemon \
--db db.json \
--crypto bitcoin,ethereum \
--timeout 180 \
Expand Down
Loading

0 comments on commit ab581b0

Please sign in to comment.