Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dockerfile #118

Merged
merged 3 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 39 additions & 39 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
name: Docker Upload

on:
push:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
name: Docker Build
on: [push, pull_request]

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

permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: "6.0.100"
- name: Setup .NET Core 3.1
uses: actions/setup-dotnet@v1
with:
dotnet-version: "3.1.404"
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
- name: Prepare
id: prepare
run: |
IMAGE_NAME=hive

GIT_REPO='https://github.com/${{ github.repository }}'
DOCKER_USER=`echo ${{ github.repository_owner }} | tr '[:upper:]' '[:lower:]'`
DOCKER_IMAGE=ghcr.io/$DOCKER_USER/$IMAGE_NAME

VERSION=`git rev-parse --short HEAD`
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
fi

echo "git_repo=${GIT_REPO}" >> $GITHUB_OUTPUT
echo "docker_user=${DOCKER_USER}" >> $GITHUB_OUTPUT
echo "docker_image=${DOCKER_IMAGE}" >> $GITHUB_OUTPUT
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
registry: ghcr.io
username: ${{ steps.prepare.outputs.docker_user }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
- name: Build and Push
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: ${{ (github.ref == 'refs/heads/master') || (contains(github.ref, 'refs/tags/') == true) }}
tags: |
${{ steps.prepare.outputs.docker_image }}:latest
${{ steps.prepare.outputs.docker_image }}:${{ steps.prepare.outputs.version }}
build-args: |
GIT_VERSION=${{ steps.prepare.outputs.version }}
GIT_REPO=${{ steps.prepare.outputs.git_repo }}
cache-from: type=gha
cache-to: type=gha,mode=max
72 changes: 41 additions & 31 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,49 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
# syntax=docker/dockerfile:1.4
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /build

# Base ASP.NET image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY ./Hive.sln .
COPY ./Directory.Build.props .
COPY ./Directory.Build.targets .
COPY ./NuGet.Config .
COPY ./NuGetInfo.props .

# Build Hive
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["NuGet.Config", "."]
COPY ["src/Hive/Hive.csproj", "src/Hive/"]
COPY ["src/Hive.Plugins/Hive.Plugins.csproj", "src/Hive.Plugins/"]
COPY ["src/Hive.Analyzers/Hive.Analyzers.csproj", "src/Hive.Analyzers/"]
COPY ["src/CodeGen/Hive.CodeGen/Hive.CodeGen.csproj", "src/CodeGen/Hive.CodeGen/"]
COPY ["src/CodeGen/Hive.CodeGen.Attributes/Hive.CodeGen.Attributes.csproj", "src/CodeGen/Hive.CodeGen.Attributes/"]
COPY ["src/Hive.Utilities/Hive.Utilities.csproj", "src/Hive.Utilities/"]
COPY ["src/Hive.Versioning/Hive.Versioning.csproj", "src/Hive.Versioning/"]
COPY ["src/Hive.Permissions/Hive.Permissions.csproj", "src/Hive.Permissions/"]
COPY ["src/Hive.Dependencies/Hive.Dependencies.fsproj", "src/Hive.Dependencies/"]
COPY ./src/Hive/Hive.csproj ./src/Hive/
COPY ./src/Hive.Plugins/Hive.Plugins.csproj ./src/Hive.Plugins/
COPY ./src/Hive.Analyzers/Hive.Analyzers.csproj ./src/Hive.Analyzers/
COPY ./src/CodeGen/Hive.CodeGen/Hive.CodeGen.csproj ./src/CodeGen/Hive.CodeGen/
COPY ./src/CodeGen/Hive.CodeGen.Attributes/Hive.CodeGen.Attributes.csproj ./src/CodeGen/Hive.CodeGen.Attributes/
COPY ./src/Hive.Utilities/Hive.Utilities.csproj ./src/Hive.Utilities/
COPY ./src/Hive.Versioning/Hive.Versioning.csproj ./src/Hive.Versioning/
COPY ./src/Hive.Permissions/Hive.Permissions.csproj ./src/Hive.Permissions/
COPY ./src/Hive.Dependencies/Hive.Dependencies.fsproj ./src/Hive.Dependencies/
RUN dotnet restore "src/Hive/Hive.csproj"
COPY . .
WORKDIR "/src/src/Hive"
RUN dotnet build "Hive.csproj" -c Release -o /app/build

# Publish Hive
FROM build AS publish
COPY ./.git ./.git/
COPY ./src ./src/
COPY ./tools ./tools/

WORKDIR /build/src/Hive
RUN dotnet publish "Hive.csproj" -c Release -o /app/publish --framework net6.0

# Pull in HiveCorePlugins
FROM ghcr.io/atlas-rhythm/hivecoreplugins:master AS plugins
COPY ./docker-entrypoint.sh /app/publish/docker-entrypoint.sh
RUN chmod +x /app/publish/docker-entrypoint.sh

# ---
FROM ghcr.io/atlas-rhythm/hivecoreplugins:master AS core-plugins

# Copy files into final image and run
FROM base AS final
# ---
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=plugins /Plugins /app/plugins
ENTRYPOINT ["dotnet", "Hive.dll"]

COPY --from=core-plugins /Plugins /app/core-plugins
COPY --from=build /app/publish .

EXPOSE 80
VOLUME ["/app/plugins"]

ARG GIT_REPO
LABEL org.opencontainers.image.source=${GIT_REPO}

ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["dotnet", "Hive.dll"]
8 changes: 8 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

# Copy core plugins if needed
if [[ -z "$HIVE_SKIP_COPY_CORE_PLUGINS" ]]; then
cp -R -u -p "/app/core-plugins/." "/app/plugins/"
fi

exec "$@"