Add Dockerfile and modify gitlab CI to build the docker
This commit is contained in:
25
.dockerignore
Executable file
25
.dockerignore
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
**/.dockerignore
|
||||||
|
**/.env
|
||||||
|
**/.git
|
||||||
|
**/.gitignore
|
||||||
|
**/.project
|
||||||
|
**/.settings
|
||||||
|
**/.toolstarget
|
||||||
|
**/.vs
|
||||||
|
**/.vscode
|
||||||
|
**/.idea
|
||||||
|
**/*.*proj.user
|
||||||
|
**/*.dbmdl
|
||||||
|
**/*.jfm
|
||||||
|
**/azds.yaml
|
||||||
|
**/bin
|
||||||
|
**/charts
|
||||||
|
**/docker-compose*
|
||||||
|
**/Dockerfile*
|
||||||
|
**/node_modules
|
||||||
|
**/npm-debug.log
|
||||||
|
**/obj
|
||||||
|
**/secrets.dev.yaml
|
||||||
|
**/values.dev.yaml
|
||||||
|
LICENSE
|
||||||
|
README.md
|
@@ -1,21 +1,36 @@
|
|||||||
stages:
|
# To contribute improvements to CI/CD templates, please follow the Development guide at:
|
||||||
- build
|
# https://docs.gitlab.com/ee/development/cicd/templates.html
|
||||||
|
# This specific template is located at:
|
||||||
|
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml
|
||||||
|
|
||||||
variables:
|
# Build a Docker image with CI/CD and push to the GitLab registry.
|
||||||
DOTNET_CLI_TELEMETRY_OPTOUT: "1"
|
# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
|
||||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1"
|
#
|
||||||
|
# This template uses one generic job with conditional builds
|
||||||
|
# for the default branch and all other (MR) branches.
|
||||||
|
|
||||||
before_script:
|
docker-build:
|
||||||
- apt-get update && apt-get install -y tar
|
# Use the official docker image.
|
||||||
|
image: docker:cli
|
||||||
build:
|
|
||||||
stage: build
|
stage: build
|
||||||
image: mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim
|
services:
|
||||||
|
- docker:dind
|
||||||
|
variables:
|
||||||
|
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG
|
||||||
|
before_script:
|
||||||
|
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
|
||||||
|
# All branches are tagged with $DOCKER_IMAGE_NAME (defaults to commit ref slug)
|
||||||
|
# Default branch is also tagged with `latest`
|
||||||
script:
|
script:
|
||||||
- dotnet nuget add source https://pkgs.dev.azure.com/tgbots/Telegram.Bot/_packaging/release/nuget/v3/index.json -n Telegram.Bot
|
- docker build --pull -t "$DOCKER_IMAGE_NAME" .
|
||||||
- dotnet restore --no-cache
|
- docker push "$DOCKER_IMAGE_NAME"
|
||||||
- dotnet publish -c Release -r linux-x64 --self-contained true /p:PublishSingleFile=true /p:PublishTrimmed=false /p:EnableCompressionInSingleFile=true
|
- |
|
||||||
- tar -czvf publish.tar.gz -C bin/Release/net9.0/linux-x64/publish/ .
|
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
|
||||||
artifacts:
|
docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest"
|
||||||
paths:
|
docker push "$CI_REGISTRY_IMAGE:latest"
|
||||||
- publish.tar.gz
|
fi
|
||||||
|
# Run this job in a branch where a Dockerfile exists
|
||||||
|
rules:
|
||||||
|
- if: $CI_COMMIT_BRANCH
|
||||||
|
exists:
|
||||||
|
- Dockerfile
|
||||||
|
21
Dockerfile
Executable file
21
Dockerfile
Executable file
@@ -0,0 +1,21 @@
|
|||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0-bookworm-slim-amd64 AS base
|
||||||
|
USER $APP_UID
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:9.0-bookworm-slim-amd64 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["mstdnCats.csproj", "./"]
|
||||||
|
RUN dotnet restore "mstdnCats.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/"
|
||||||
|
RUN dotnet build "mstdnCats.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "mstdnCats.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "mstdnCats.dll"]
|
@@ -6,6 +6,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
|
<JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Reference in New Issue
Block a user