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 47d0ebd
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 33 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
41 changes: 15 additions & 26 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#######################
# Step 1: Base target #
#######################
FROM node:20 as development
FROM --platform=$BUILDPLATFORM 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,57 +17,47 @@ 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"]

##########################
# Step 3: "build" target #
##########################
FROM development as build
FROM --platform=$BUILDPLATFORM development as build
ARG app_path

WORKDIR /$app_path
WORKDIR $app_path

ADD src ./src

COPY tsconfig.json ./

RUN npm run build && tar czvf dist.tar.gz dist
RUN npm run build

###############################
# Step 4: "production" target #
###############################
FROM node:20-alpine3.18 as production
ARG port
FROM --platform=$BUILDPLATFORM node:20-alpine as production
ARG app_path

WORKDIR /$app_path
WORKDIR $app_path

COPY package.json ./
ADD src ./src
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}/

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}
COPY --from=build ${app_path}/node_modules ${app_path}/node_modules
COPY --from=build ${app_path}/dist ${app_path}/dist

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
5 changes: 1 addition & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
"src/@types/*"
]
}
},
"include": [
"src/**/*"
]
}
}

0 comments on commit 47d0ebd

Please sign in to comment.