Skip to content

Instantly share code, notes, and snippets.

@zerda
Last active August 8, 2023 07:52
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save zerda/a4af9f32357c87a3df3e002623bd995c to your computer and use it in GitHub Desktop.
Save zerda/a4af9f32357c87a3df3e002623bd995c to your computer and use it in GitHub Desktop.
Gitlab CI for ASP.Net Core project
stages:
- build
- publish
.build: &build_template
stage: build
image: microsoft/dotnet:2.1-sdk-alpine
cache:
key: "$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME"
paths:
- .nuget/
script:
- dotnet restore -s https://api.nuget.org/v3/index.json --packages ./.nuget/
- dotnet publish --no-restore -c Release -o ./docker/publish/
develop_build:
<<: *build_template
only:
- develop
artifacts:
expire_in: 1 day
paths:
- docker/
.docker: &docker_template
stage: publish
image: docker:stable-dind
script:
- mkdir docker/app/
- mv docker/publish/$ASSEMBLY_NAME.* docker/app/
- mv docker/publish/*.config docker/app/
- mv docker/publish/*.json docker/app/
- cp Dockerfile docker/
- docker build -t $TAG ./docker/
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $TAG
develop_docker:
<<: *docker_template
only:
- develop
dependencies:
- develop_build
variables:
ASSEMBLY_NAME: app
TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_PIPELINE_ID
FROM microsoft/dotnet:2.1-runtime-alpine
# application, runtime & dependency files should be in different layers
COPY publish/ /app/
COPY app/ /app/
WORKDIR /app
# app(.dll) should be $ASSEMBLY_NAME
ENTRYPOINT ["dotnet", "app.dll"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment