mirror of
https://github.com/orangecoding/fredy.git
synced 2026-06-16 12:31:07 +00:00
Refactor Docker build and automatically push images (#41)
Refactor Docker build / Add GitHub workflow for creating and publishing Docker image
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
node_modules
|
node_modules/
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
test
|
test/
|
||||||
|
conf/
|
||||||
|
db/
|
||||||
|
.git/
|
||||||
|
.github/
|
||||||
|
|||||||
46
.github/workflows/docker.yml
vendored
Normal file
46
.github/workflows/docker.yml
vendored
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: Create and publish Docker image
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'master'
|
||||||
|
tags:
|
||||||
|
- '*'
|
||||||
|
|
||||||
|
env:
|
||||||
|
REGISTRY: ghcr.io
|
||||||
|
IMAGE_NAME: ${{ github.repository }}
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push-image:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v1
|
||||||
|
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Log in to the Container registry
|
||||||
|
uses: docker/login-action@v1
|
||||||
|
with:
|
||||||
|
registry: ${{ env.REGISTRY }}
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract metadata (tags, labels) for Docker
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v3
|
||||||
|
with:
|
||||||
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v2
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
18
Dockerfile
Normal file
18
Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# syntax=docker/dockerfile:1.3
|
||||||
|
FROM node:16-alpine AS builder
|
||||||
|
COPY --chown=1000:1000 . /fredy
|
||||||
|
WORKDIR /fredy
|
||||||
|
USER 1000
|
||||||
|
RUN yarn install
|
||||||
|
RUN yarn run prod
|
||||||
|
|
||||||
|
FROM node:16-alpine
|
||||||
|
COPY --from=builder --chown=1000:1000 /fredy /fredy
|
||||||
|
RUN mkdir /db /conf && \
|
||||||
|
chown 1000:1000 /db /conf && \
|
||||||
|
ln -s /db /fredy/db && ln -s /conf /fredy/conf
|
||||||
|
EXPOSE 9998
|
||||||
|
USER 1000
|
||||||
|
VOLUME [ "/conf", "/db" ]
|
||||||
|
WORKDIR /fredy
|
||||||
|
CMD node index.js --no-daemon
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
FROM alpine:latest AS build
|
|
||||||
# use given repository, default below:
|
|
||||||
ARG repo=https://github.com/orangecoding/fredy.git
|
|
||||||
|
|
||||||
RUN mkdir -p /usr/src/
|
|
||||||
#Install Software
|
|
||||||
RUN apk add --update nodejs npm git
|
|
||||||
|
|
||||||
# Output used repository
|
|
||||||
RUN echo "Cloning from $repo"
|
|
||||||
|
|
||||||
RUN cd /usr/src && git clone $repo
|
|
||||||
|
|
||||||
RUN ln -s /usr/src/fredy/conf/ /conf
|
|
||||||
|
|
||||||
# create db folder
|
|
||||||
RUN mkdir /usr/src/fredy/db/
|
|
||||||
|
|
||||||
RUN ln -s /usr/src/fredy/db/ /db
|
|
||||||
|
|
||||||
RUN npm i -g yarn
|
|
||||||
|
|
||||||
RUN cd /usr/src/fredy/ && yarn
|
|
||||||
|
|
||||||
WORKDIR /usr/src/fredy
|
|
||||||
|
|
||||||
RUN yarn run prod
|
|
||||||
|
|
||||||
EXPOSE 9998
|
|
||||||
|
|
||||||
VOLUME [ "/conf", "/db" ]
|
|
||||||
# --no-daemon is required for keeping Container alive
|
|
||||||
CMD node index.js --no-daemon
|
|
||||||
@@ -4,10 +4,8 @@ services:
|
|||||||
container_name: fredy
|
container_name: fredy
|
||||||
# build from empty build folder to reduce size of image
|
# build from empty build folder to reduce size of image
|
||||||
build:
|
build:
|
||||||
context: ./build
|
context: .
|
||||||
dockerfile: Dockerfile
|
dockerfile: Dockerfile
|
||||||
args:
|
|
||||||
repo: https://github.com/orangecoding/fredy.git
|
|
||||||
image: fredy/fredy
|
image: fredy/fredy
|
||||||
# map existing config and database
|
# map existing config and database
|
||||||
volumes:
|
volumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user