باستخدام حركات GitHub لبناء ودفع صورة الدوكر (العربية (Arabic))

باستخدام حركات GitHub لبناء ودفع صورة الدوكر

Tuesday, 30 July 2024

//

3 minute read

هذا مثال بسيط عن كيفية استخدام حركات GitHub لبناء ودفع صورة الدوكر إلى سجل حاويات

المتطلبات الأساسية

  • هناك файл Docker للمشاريع التي تريد بناءها ودفعها
  • يوجد مخزن GitHub للمشروع.
  • يوجد registru container لدفع الصورة إلى.
  • سجل الدوكر 'اسم المستخدم وكلمة المرور (في مخابرات غويت هاب )

لهذا المشروع بدأت بمشروع اساسي .NET Core ASP.NET ونموذج Dockerfile العادي الذي صنعه Rider

الدوكرفيل

هذا "دوكرفيل" هو بناء مرحلي متعدد - يبني المشروع ومن ثم ينسخ المخرج إلى صورة في وقت التشغيل

بالنسبة لهذا الاقتراح, كما أستخدم TailwindCSS, أحتاج أيضاً إلى ដំឡើង NodeM SK2js وتشغيل بولد بناء Tail windCSS .

# Install Node.js v20.x
RUN apt-get update && apt-get install -y curl \
    && curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh \
    && bash nodesource_setup.sh \
    && apt-get install -y nodejs \
    && rm -f nodesource_setup.sh \
    && rm -rf /var/lib/apt/lists/*

هذا يقوم بتحميل آخر ( في الوقت الذي يكتب فيه) نسخة من العقدةM SK2js ويقوم بتركيبها في صورة البناء

لاحقاً في الملف


FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release

# Install Node.js v20.x
RUN apt-get update && apt-get install -y curl \
    && curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh \
    && bash nodesource_setup.sh \
    && apt-get install -y nodejs \
    && rm -f nodesource_setup.sh \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /src
COPY ["Mostlylucid/Mostlylucid.csproj", "Mostlylucid/"]
RUN dotnet restore "Mostlylucid/Mostlylucid.csproj"
COPY . .
WORKDIR "/src/Mostlylucid"

# Copy package.json and package-lock.json and install npm dependencies
COPY package*.json ./
RUN npm install

# Ensure npm-run-all is available and install npm dependencies
RUN npm --version
RUN npx tailwindcss -i ./src/css/main.css -o ./wwwroot/css/dist/main.css

RUN dotnet build "Mostlylucid.csproj" -c $BUILD_CONFIGURATION -o /app/build


FROM build AS publish
RUN dotnet publish "Mostlylucid.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Mostlylucid.dll"]

حركات GitHub

عمل GitHub لهذا الموقع هو عمل بناء وضغط بسيط يتم تنشيطه عند الضغط على فرع الرئيسي. https://githubM SK1com/scottgalMSC3mostlylucidwebMスク4blobMST5mainMSSK6gitHubMSR7workflowsMSS8dockerM SS9imageMISS10yml

هذا الإجراء يتحقق من المخزن, يسجل في هب الدوكر, ينشئ بناء الدوكرxM SK2 يحفظ طبقات الدوكر*, يبني ويضع علامات على صورة الدوكر+, ثم يضغط على الصورة إلى هب دوكر

في دوتنه تأليف Docker

name: Docker Image CI

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build-and-push:
    runs-on: ubuntu-latest

    steps:
    - name: Check out the repository
      uses: actions/checkout@v4

    - name: Log in to Docker Hub
      run: echo "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USER_NAME }}" --password-stdin

    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v2

    - name: Cache Docker layers
      uses: actions/cache@v3
      with:
        path: /tmp/.buildx-cache
        key: ${{ runner.os }}-buildx-${{ github.sha }}
        restore-keys: |
          ${{ runner.os }}-buildx-

    - name: Build and tag the Docker image
      id: build
      run: |
        TIMESTAMP=$(date +%s)
        echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV
        docker build . --file Mostlylucid/Dockerfile --tag ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid:latest --tag ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid:$TIMESTAMP

    - name: Push the Docker image to Docker Hub
      run: |
        docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid:latest
        docker push ${{ secrets.DOCKER_HUB_USER_NAME }}/mostlylucid:${{ env.TIMESTAMP }}
Finding related posts...
logo

© 2026 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.