Hello guys, my problem is simple but I cant find the solution.
I have 2 branches, main and development. Every new modification I create a feature branch, then when everything is fine I made a push. Now I would like that my pipeline run on that branch that I just created and pushed and upload my project with that branch online.
Right now indeed I need to push on main in order to get my modification up and running online.
I made the dockerfile in order to publish my dotnet application on cloud run and from my gitlab-ci.yml I build the project and then deploy on gcloud.
What I want accomplish is: every time a made a push on a feature branch, having the whole application online up and running instead of merging the branch onto development and then onto main, because right now my pipeline somehow just upload the code on the main branch.
These are my files
stages:
- build
- publish
#BUILD
build_production:
image: docker:stable
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
only:
- branches
stage: build
script:
# ADD GOOGLE SERVICE KEY
- touch ${HOME}/gcloud-service-key.json
- echo "${GCLOUD_SERVICE_KEY}" > ${HOME}/gcloud-service-key.json
- cd myAppAPI
# BUILD AND UPLOAD TO GOOGLE REPO IMAGES
- docker login -u _json_key --password-stdin https://eu.gcr.io < ${HOME}/gcloud-service-key.json
- docker build --tag $IMAGE_NAME -f Dockerfile .
- docker tag $IMAGE_NAME "eu.gcr.io/$GCLOUD_PROJECT_ID/$IMAGE_NAME"
- docker push "eu.gcr.io/$GCLOUD_PROJECT_ID/$IMAGE_NAME:latest"
#PUBLISH
publish_production:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:alpine
only:
- branches
stage: publish
script:
- touch ${HOME}/gcloud-service-key.json
- echo "${GCLOUD_SERVICE_KEY}" > ${HOME}/gcloud-service-key.json
- gcloud auth activate-service-account --key-file ${HOME}/gcloud-service-key.json
- gcloud run deploy web-api --image eu.gcr.io/$GCLOUD_PROJECT_ID/$IMAGE_NAME:latest --platform managed --region europe-west1 --project $GCLOUD_PROJECT_ID
The Dockerfile
# Use Microsoft's official build .NET image.
# https://hub.docker.com/_/microsoft-dotnet-core-sdk/
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /app
EXPOSE 8080
# Install production dependencies.
# Copy csproj and restore as distinct layers.
COPY *.csproj ./
RUN dotnet restore
# Copy local code to the container image.
COPY . ./
WORKDIR /app
# Build a release artifact.
RUN dotnet publish -c Release -o out
# Use Microsoft's official runtime .NET image.
# https://hub.docker.com/_/microsoft-dotnet-core-aspnet/
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
# Run the web service on container startup.
ENTRYPOINT ["dotnet", "myAppAPI.dll"]
Thank you