diff --git a/.github/actions/build.sh b/.github/actions/build.sh deleted file mode 100755 index a22317fed..000000000 --- a/.github/actions/build.sh +++ /dev/null @@ -1,12 +0,0 @@ -VERSION=$(cat ./frontend/.env | grep VITE_ROMM_VERSION | cut -d "=" -f2) - -if [[ $GIT_BRANCH != 'master' ]]; then - VERSION=dev-$VERSION - 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 \ No newline at end of file diff --git a/.github/workflows/image.yml b/.github/workflows/image.yml index 1997b14fa..35b1e678b 100644 --- a/.github/workflows/image.yml +++ b/.github/workflows/image.yml @@ -5,22 +5,51 @@ on: [workflow_dispatch] 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 + 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 }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 492e3ee57..ab5819fc4 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -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"]