Merge pull request #142 from duhow/optimize-dockerfile

Optimize Dockerfile and build workflow
This commit is contained in:
Zurdi
2023-04-10 18:24:00 +02:00
committed by GitHub
3 changed files with 67 additions and 39 deletions

View File

@@ -1,9 +0,0 @@
if [[ $GIT_BRANCH != 'master' ]]; then
docker buildx build --push\
--tag zurdi15/romm:dev-latest --tag zurdi15/romm:dev-${VERSION}\
--platform linux/arm64 . --file ./docker/Dockerfile
else
docker buildx build --push\
--tag zurdi15/romm:latest --tag zurdi15/romm:${VERSION}\
--platform linux/arm64,linux/amd64 . --file ./docker/Dockerfile
fi

View File

@@ -11,20 +11,51 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set environment variables
run: echo "GIT_BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- name: Install buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
version: latest
- name: Login to docker hub
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
- name: Build the image
shell: bash
run: ./.github/actions/build.sh
env:
VERSION: ${{ inputs.version }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Generate Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
name=zurdi15/romm
name=ghcr.io/zurdi15/romm
flavor: |
# latest on master branch, prefix dev on other branches
latest=true
prefix=${{ github.ref != format('refs/heads/{0}', 'master') && 'dev-' || '' }},onlatest=true
tags: |
type=raw,value=${{ inputs.version }}
labels: |
org.opencontainers.image.version=${{ inputs.version }}
- name: Build image
uses: docker/build-push-action@v4
with:
file: docker/Dockerfile
context: .
push: true
platforms: linux/arm64,linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

View File

@@ -1,37 +1,43 @@
# build frontend
FROM node:lts-alpine as front-build-stage
WORKDIR /front
COPY ./frontend/package*.json ./
COPY ./frontend/package*.json .
RUN npm install
COPY ./frontend ./
COPY ./frontend .
RUN npm run build
# setup frontend
FROM ubuntu/nginx:1.18-22.04_edge as production-stage
COPY --from=front-build-stage /front/dist /var/www/html
COPY ./frontend/assets/platforms /var/www/html/assets/platforms
RUN mkdir -p /var/www/html/assets/romm
RUN ln -s /romm/library /var/www/html/assets/romm/library
RUN ln -s /romm/resources /var/www/html/assets/romm/resources
ARG WEBSERVER_FOLDER=/var/www/html
COPY --from=front-build-stage /front/dist ${WEBSERVER_FOLDER}
COPY ./frontend/assets/platforms ${WEBSERVER_FOLDER}/assets/platforms
RUN mkdir -p ${WEBSERVER_FOLDER}/assets/romm && \
ln -s /romm/library ${WEBSERVER_FOLDER}/assets/romm/library && \
ln -s /romm/resources ${WEBSERVER_FOLDER}/assets/romm/resources
# setup backend
RUN apt update
RUN apt install -y software-properties-common gcc
RUN add-apt-repository -y ppa:deadsnakes/ppa
RUN apt update -y && apt install libmariadb3 libmariadb-dev -y
RUN apt install -y python3.10 python3-pip
RUN apt update && \
apt install -y --no-install-recommends ca-certificates curl gnupg && \
# add deadsnakes ppa for Python versions
echo "deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy main" > /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-jammy.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F23C5A6CF475977595C89F51BA6932366A755776 && \
apt update && \
apt install -y --no-install-recommends \
libmariadb3 libmariadb-dev gcc \
python3.10 python3.10-dev python3-pip && \
apt autoremove && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
WORKDIR /back
COPY ./backend/requirements.txt ./requirements.txt
RUN pip install --upgrade pip
RUN pip install --no-cache-dir --upgrade -r ./requirements.txt
COPY ./backend/src ./
RUN pip install --no-cache --upgrade pip && \
pip install --no-cache --upgrade -r requirements.txt
COPY ./backend/src .
# setup init script and config files
COPY ./docker/init_scripts/init_back /init_back
COPY ./docker/init_scripts/init_front /init_front
COPY ./docker/init_scripts/init /init
COPY ./docker/init_scripts/* /
COPY ./docker/nginx/default.conf /etc/nginx/nginx.conf
EXPOSE 80
WORKDIR /romm
CMD ["/init"]