Skip to content

Commit

Permalink
👷 Add CI for building docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianpb committed Mar 4, 2024
1 parent fb17c5c commit 4cd2699
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 22 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
name: Build & publish

on:
push:
# Sequence of patterns matched against refs/heads
branches:
- "**" # Push events on all branchs
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
publish:
name: Build package
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- uses: actions/checkout@v4
- name: 🏗 Build
run: make build
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64,arm/v7
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
target: production
build-args:
app_path=rhasspy-handler
NPM_VERBOSE=1
31 changes: 12 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
FROM node:20 as development

ARG NPM_VERBOSE
ARG port
ARG app_path

# Base dir /app
WORKDIR /$app_path
WORKDIR $app_path

COPY package.json ./

Expand All @@ -18,16 +17,13 @@ RUN if [ -z "${NPM_VERBOSE}" ]; then\
npm install --verbose; \
fi

VOLUME /${app_path}/src
VOLUME /${app_path}/dist
VOLUME /${app_path}/tests
VOLUME /${app_path}/data
VOLUME ${app_path}/src
VOLUME ${app_path}/dist
VOLUME ${app_path}/tests
VOLUME ${app_path}/data

COPY tsconfig.json ./

# Expose the listening port of your app
EXPOSE ${port}

CMD ["npm","run", "dev"]

##########################
Expand All @@ -36,7 +32,7 @@ CMD ["npm","run", "dev"]
FROM development as build
ARG app_path

WORKDIR /$app_path
WORKDIR $app_path

ADD src ./src

Expand All @@ -47,28 +43,25 @@ RUN npm run build && tar czvf dist.tar.gz dist
###############################
# Step 4: "production" target #
###############################
FROM node:20-alpine3.18 as production
ARG port
FROM --platform=$BUILDPLATFORM node:20-alpine3.18 as production
ARG app_path

WORKDIR /$app_path
WORKDIR $app_path

COPY package.json ./
ADD tests ./tests
ADD data ./data
VOLUME ${app_path}/data


## Install production dependencies and clean cache
#RUN npm install --production && \
# npm cache clean --force

COPY --from=build /${app_path}/node_modules /${app_path}/node_modules
COPY --from=build /${app_path}/dist.tar.gz /${app_path}/
COPY --from=build ${app_path}/node_modules ${app_path}/node_modules
COPY --from=build ${app_path}/dist.tar.gz ${app_path}/

RUN apk --no-cache add curl tar && \
tar -zxvf dist.tar.gz && \
rm -rf dist.tar.gz && apk del tar

# Expose the listening port of your app
EXPOSE ${port}

CMD ["npm","run", "start"]
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# Directory to save podcast
# Mopidy saves this in /var/lib/mopidy/media
export APP = rhasspyhandler
export APP = rhasspy-handler
export APP_PATH := $(shell pwd)
export PODCAST_DIR=media
export NPM_VERBOSE ?= 1
export DEVICE=raspberry
export PORT=8000

dummy := $(shell touch artifacts)
include ./artifacts
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ services:
app_path: /${APP}
NPM_VERBOSE: ${NPM_VERBOSE}
environment:
- port=${PORT}
- app_path=${APP}
- PODCAST_DIR=${PODCAST_DIR}
- DEVICE=${DEVICE}
Expand Down

0 comments on commit 4cd2699

Please sign in to comment.