How to containerize .Net project when using Shared library - asp.net

So I have a .net app with file structure:
-MyApp
|__Client
|__Server
|__Shared
Inside Shared directory I have defined a model for users to subscribe.
Subscriber.cs
public class Subscriber { }
Inside Client directory, I used this shared Subscriber model.
public interface ISubscriberService
{
IList<Subscriber> Subscribers { get; set; }
}
Inside Server directory
public IEnumerable<Subscriber> Get()
{
List<Subscriber> subscribers = _unitOfWork.Subscribers.GetAll().ToList();
return subscribers;
}
Now Here's when I ran into problems.
So I needed to Dockerize MyApp project, I placed a Dockerfile inside client, although this creates a problem, the Subscriber model is in the Shared directory. Its (forbidden path) to COPY ../Shared . , nor do I find placing one dockerfile in main directory and specifing Client, Server, and Shared builds confiuration.
example:
-MyApp
|__Client
|__Server
|__Shared
|__Dockerfile
My solution facing this problem, was instead of using one docker file, was to use multiple
-MyApp
|__Client
|__Server
|__Shared
|__Dockerfile.Client
|__Dockerfile.Server
Feel like this will allow me more control, when accessing the shared library any sugestions.

SOLVED
docker-compose.yml
library:
build:
context: ./Shared
dockerfile: dockerfile
client:
build:
context: ./Client
dockerfile: dockerfile
depends_on:
- library
server:
build:
context: ./Server
dockerfile: dockerfile
depends_on:
- library
So creating a docker-compose file then telling docker directory depends_on another directory (shared library) solves it.
*EDIT
Never mind first solution seem to work correctly wonder if there's another solution where i can place my dockerfiles into the project solution rather then outside then cd into it

Related

Lando has trouble accessing a URL from a non-Lando app on my system

My company has software that runs within Docker on my system, but is not using Lando. This software is serving some data via the URL:
http://local.relay.cool:8081/clicks-bff/api/ads/
I can hit this URL in an anonymous browser, cURL it from the terminal, and load it via Postman and it returns the expected data.
I'm running Lando with the Wordpress recipe and I'm developing a plugin. This plugin can hit external URLs and retrieve data, I've tried with several different ones just to confirm.
However when Lando attempts to hit the URL listed above I get a WP_Error:
object(WP_Error)#1269 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(58) "cURL error 28: Resolving timed out after 5514 milliseconds" } } ["error_data"]=> array(0) { } }
Here's the .lando.yaml config block:
name: my app name
recipe: wordpress
config:
webroot: wordpress
Is there some configuration option that I'm missing to allow Lando access to another URL on my machine?
From your question, it sounds like the URL you're trying to access is running on a non-Lando docker container on your machine.
This means routing from your Lando instance to the service will be a bit different that usual. You should be able to accomplish this the same way you would access localhost endpoints. As explained in this Lando issue on GitHub, you must use the $LANDO_HOST_IP environment variable to route to local services.
Since your containers are all running inside of a light hyper-v instance you'll need to know the hostname or IP of the host machine. Generally we set $LANDO_HOST_IP to your computer . . .
So try something like this (assuming you're using PHP's curl):
curl_init('http://' . $_ENV["LANDO_HOST_IP"] . ':8081/clicks-bff/api/ads/');

Change Symfony public directory to fit website

I want to create directory called 'app' in my public directory and make it root of my application instead of 'public' dir. What should I do except adding:
"extra": {
"public-dir": "public/app/",
...
}
I got a vue app that should be placed in 'app' directory and a wordpress instance that will be placed in 'public' directory so when I enter www.mywebsite.com I get wordpress website, and when I enter www.mywebsite.com/app I got my symfony/vue app.
So far I edited my webpack.config.js with:
.setOutputPath("public/app/build/")
.setPublicPath("/build/")
And it think it works on dev env but in prod env when i hit www.mywebsite.com/app I got:
<script src="/build/app.js"></script>
Which wrongly points to: www.mywebsite.com/build/app.js instead of www.mywebsite.com/app/build/app.js
But whenever I change webpack.config.js to:
.setOutputPath("public/app/build/")
.setPublicPath("/app/build/")
It works on production but not on dev env.
What am I doing wrong here?
Going by your problem description I'm assuming your application is accessed at / in your dev environment, but /app in your prod environment as explained. So you have to take that into account when calling .setConfigPath() by checking the environment you are running in your webpack config:
.setPublicPath(Encore.isProduction() ? '/app/build' : '/build')

Concourse unauthorized error pushing to Artifactory using docker-image-resource

I'm trying to use Concourse to grab a dockerfile defintion from a git repository, do some work, build the docker image, and push the new image to Artifactory. See below for the pipeline definition. At this time I have all stages up to the artifactory stage (the one that pushes to Artifactory) working. The artifactory stage exits with error with the following output:
waiting for docker to come up...
sha256:c6039bfb6ac572503c8d97f42b6a419b94139f37876ad331d03cb7c3e8811ff2
The push refers to repository [artifactory.server.com:2077/base/golang/alpine]
a4ab5bf94afd: Preparing
unauthorized: The client does not have permission to push to the repository.
This would seem straight-forward as an Artifactory permissions issue, except that I've tested locally with the docker cli and am able to push using the same user/pass as specified within destination_username and destination_password. I double checked the credentials to make sure I'm using the same ones and find that I am.
Question #1: is there any other known cause for getting this error? I've scoured the resource github page without finding anything. Any ideas why I may be getting the permissions error?
Without having an answer to the above question, I'd really like to dig deeper into troubleshooting the problem. To do so I use fly hijack to get a shell in the corresponding container. I notice that docker is installed on the container, so next step I think would be to do a docker import on the tarball for the image I'm trying to push and then perform a docker push to push it to the repo. When attempting to run the import I get the error:
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is
the docker daemon running?
Question #2: Why can't I use docker commands from within the container? Perhaps this has something to do with the issue I'm seeing with pushing to repo when running the pipeline (I don't think so)? Is it because the container isn't running with privilege? I thought that the privileged argument would be supplied in the resource type definition, but if not, how can I run with privilege?
resources:
- name: image-repo
type: git
source:
branch: master
private_key: ((private_key))
uri: ssh://git#git-server/repo.git
- name: artifactory
type: docker-image
source:
repository: artifactory.server.com:2077/((repo))
tag: latest
username: ((destination_username))
password: ((destination_password))
jobs:
- name: update-image
plan:
- get: image-repo
- task: do-stuff
file: image-repo/scripts/do-stuff.yml
vars:
repository-directory: ((repo))
- task: build-image
privileged: true
file: image-repo/scripts/build-image.yml
- put: artifactory
params:
import_file: image/image.tar
Arghhhh. Found after much troubleshooting that the destination_password wasn't being picked up properly due to special characters and a lack of quotes. Fixed the issue by properly setting the password within yaml file being included with the --load-vars flag.

Hosting Symfony 4 app with EasyDeployBundle on server without /usr/local/bin/composer

For a Symfony 4 app I have chosen a Web Cloud plan from the hosting provider OVH.
For the deployment I have decided to use the EasyDeployBundle which looks very promising. This is my config file:
<?php
use EasyCorp\Bundle\EasyDeployBundle\Deployer\DefaultDeployer;
return new class extends DefaultDeployer
{
public function configure()
{
return $this->getConfigBuilder()
->server('ovh')
->deployDir('directory/path/at/server')
->repositoryUrl('git#github.com:foo/bar.git')
->repositoryBranch('master')
;
}
}
I have .ssh/config file with the following entry:
Host ovh
Hostname sshcloud.foobar.hosting.ovh.net
Port 12345
User foobar
Note: all values are dummies, just for illustrational purposes.
When I run:
php bin/console deploy --dry-run -v
everything goes fine, but when I actually try to deploy I get the following error:
The command "ssh ovh 'which /usr/local/bin/composer'" failed.
The problem is that I have no write-access to the directory /usr/local/bin/ on the server. The composer.phar is in my home directory and I can't move it to the provisioned destination.
Is there any possibility to tell EasyDeployBundle to look for composer in another directory?
I should really read the manuals, in particular when I'm linking them in my question.
There is a method remoteComposerBinaryPath that accepts custom path to composer. I have amended the method configure like this:
public function configure()
{
return $this->getConfigBuilder()
->server('ovh')
->deployDir('directory/path/at/server')
->repositoryUrl('git#github.com:foo/bar.git')
->repositoryBranch('master')
->remoteComposerBinaryPath('composer.phar')
;
}
On the server I created .bashrc in my home folder and added the line:
export PATH=$PATH:/home/foobar
and now the deployment is passing this hurdle.
I have now another problem, but at least this one is solved and maybe the answer can help other people too.

Symfony 2 how to create a parameters_dev.yml?

i just started coding with Symfony 2. On my local machine i setup my database using app/console doctrine:database:create and doctrine:schema:create which works great.
The problem i have is, local i have diffrent parameters defined in parameters.yml than on my production environment. How can i define paramters for dev and for prod? I've already tried to create a parameters_dev.yml but this did not work.
Should i maybe create a paramters.yml on my prod server and copy it after deployment so i dont have my DB password in version control?
parameters.yml should't be handled by version control.
You have to set it on ignore in .gitignore.
Only parameters.yml.dist has to be versioned
more over if you use symfony 2.3 and install vendors using composer on prod you will be prompt to enter all the setting from parameters.yml.dist so parameters.yml will be generated automatically
In Symfony 2.7 I had to add this to appKernel.php:
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/parameters_'.$this->getEnvironment().'.yml');
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
And then create both parameters_dev.yml and parameters_prod.yml.
Don’t forget to add this:
imports:
- { resource: parameters.yml }
on the first line of each new ymls.

Resources