Error when trying to run npm build on gitlab-ci with terraform - amazon-s3

I'm new to terraform but I've been fairly successful so far. I'm trying to get a mithril app to be built and deployed fully with terraform and gitlab to aws s3 and cloudfront. It is failing on this block here:
data "external" "frontend_build" {
program = ["bash", "-c",
<<EOT
(npm ci && npm run build -- --env.PARAM="$(jq -r '.param')") >&2 && echo "{\"dest\": \"dist\"}"
EOT
]
working_dir = "${path.module}/frontend"
query = {
param = "Hi from Terraform!"
}
}
Here is the error message from gitlab:
Error: External Program Lookup Failed
│
│ with data.external.frontend_build,
│ on data.tf line 2, in data "external" "frontend_build":
│ 2: program = ["bash", "-c", <<EOT
│ 3: (npm ci && npm run build -- --env.PARAM="$(jq -r '.param')") >&2 && echo "{\"dest\": \"dist\"}"
│ 4: EOT
│ 5: ]
│
│ The data source received an unexpected error while attempting to find the
│ program.
│
│ The program must be accessible according to the platform where Terraform is
│ running.
│
│ If the expected program should be automatically found on the platform where
│ Terraform is running, ensure that the program is in an expected directory.
│ On Unix-based platforms, these directories are typically searched based on
│ the '$PATH' environment variable. On Windows-based platforms, these
│ directories are typically searched based on the '%PATH%' environment
│ variable.
│
│ If the expected program is relative to the Terraform configuration, it is
│ recommended that the program name includes the interpolated value of
│ 'path.module' before the program name to ensure that it is compatible with
│ varying module usage. For example: "${path.module}/my-program"
│
│ The program must also be executable according to the platform where
│ Terraform is running. On Unix-based platforms, the file on the filesystem
│ must have the executable bit set. On Windows-based platforms, no action is
│ typically necessary.
│
│ Platform: linux
│ Program: bash
│ Error: exec: "bash": executable file not found in $PATH
I got this code from a tutorial so it may be outdated, but I can't find anyone else talking about this particular thing.
EDIT:
Here is my .gitlab-ci.yml
include:
- template: Terraform.latest.gitlab-ci.yml
variables:
TF_STATE_NAME: default
TF_CACHE_KEY: default
TF_ROOT: terraform/

Related

take the structure of any project

I have seen the project structure on readMe, how can I take this structure of my project, any program? any website. doesn't seems right to me to create by hand?
Yes, there is a very simple way to get it.
Navigate to the root folder of your project and run tree from your terminal. You should get something like this:
project_root
│ README.md
│
└───some_folder
│ │ another_file.txt
│ │ some_code.code
│ │
│ └───some_subfolder
│ │ some_more_code.txt
│ │ another_file.txt
│ │ a_picture.png
│ │ ...
│
└───another_folder
│ more_files.txt
│ more_code.code
...
Now you can copy and paste this tree into your README file, wrapping it in triple backticks - ``` to get the markdown styling.
https://ascii-tree-generator.com/ --> by hand ***
or ***
tree command in powershell --> auto

How to fix Conflicting distribution for my local apt repo?

I was trying to make an apt repo. I have this deb which is not architecture dependant and this is the structure of my repo:
.
├── dists
│ └── testing
│ ├── InRelease
│ ├── main
│ │ ├── Packages
│ │ └── Packages.gz
│ ├── Release
│ └── Release.gpg
├── KEY.gpg
└── pool
└── testing
└── main
└── s
└── savcli
└── savcli_0.0.1_all.deb
I add deb <uri-to-repo> testing main to my sources.list. I also add the key, But when I apt update I get these errors:
W: Conflicting distribution: <uri-to-repo> testing InRelease (expected testing but got )
W: Skipping acquire of configured file 'main/binary-amd64/Packages' as repository '<uri-to-repo> testing InRelease' does not seem to provide it (sources.list entry misspelt?)
W: Skipping acquire of configured file 'main/binary-i386/Packages' as repository '<uri-to-repo> testing InRelease' does not seem to provide it (sources.list entry misspelt?)
I'm not sure what's wrong and how I can fix this. I don't want to make a flat repo and add [trusted=yes]. So what have I done wrong?
It seems that you are missing configuration details in the release and in release files some examples of how a Release File should look like are. You can see more examples here https://lists.debian.org/debian-mentors/2006/04/msg00294.html and Configuring reprepro https://wiki.debian.org/DebianRepository/SetupWithReprepro#Generating_OpenPGP_keys
I used apt-ftparchive to genereate my release file and so I used the following CLI command
apt-ftparchive \
-o APT::FTPArchive::Release::Origin="my app" \
-o APT::FTPArchive::Release::Label="my app" \
-o APT::FTPArchive::Release::Architectures="arm64" \
-o APT::FTPArchive::Release::Components="main" \
-o APT::FTPArchive::Release::Description="Apt repository for my app" \
-o APT::FTPArchive::Release::Codename="stable" \
-o APT::FTPArchive::Release::Suite="main" \
release ./dists/stable/ > ./dists/stable/Release
The Release File output will look somthing similar too
Architectures: arm64
Codename: stable
Components: main
Date: Tue, 27 Dec 2022 14:53:28 +0000
Description: Apt repository for my app
Label: My App
Origin: My App
Suite: main
MD5Sum:
f948e3b9ecc3ee1bb89490eec5a897e8 197 Release
50101e65a457f7adfdb11be49f36e2e4 600 main/binary-arm64/Packages
ff153fcc8b9f9f49d0c917afd97bff72 454 main/binary-arm64/Packages.gz
SHA1:
3f9bdf152d1060d28faef385f22e2b3a39bdba95 197 Release
5648155184dabe68f8b01f09d4c70afee215f289 600 main/binary-arm64/Packages
7582505ccae55b2d624f8d3ae42ec5104ddad057 454 main/binary-arm64/Packages.gz
SHA256:
1abb7494951bbdeb04a5e0fc8124b35144a7d22b16c6716e18a140135328fa82 197 Release
afbb25d8792a6377c8b63b8fe3754419337eed319cfb546945cecc95d3207f3b 600 main/binary-arm64/Packages
7cfc6394fc938e0824c82ea15a03dfa1e72c5d344e8d85abeb4d317b0b643fc3 454 main/binary-arm64/Packages.gz
SHA512:
d8c327407e2eca79a58db5934ebbe617198778fa34b9a506dc6c9ac57f3f680658e8c069f15af58eb75a27596166b6e2ee6991861e05f5346ea503874ab2aa88 197 Release
e275bdc954cfbf05d525c0a1c94c709411caf84bc5dd8c9e888b78d6108c4d93f7a5b31f42466ed21b740e1e69a14784f79f2815d019faaa8b411f9a30562ea1 600 main/binary-arm64/Packages
d8ccc972408816d791130076a859249b822c19183b746137ee61d765134ef59ab9e72ce43c9755c11c8540dfb55f7d573796036137f4f8296f35d8cafb79b3b6 454 main/binary-arm64/Packages.gz

lessc.cmd cannot find #import file, path resolves fine?

The above code displays the following error:
cmd.exe /D /C call C:/Users/<user>/AppData/Roaming/npm/lessc.cmd --no-color style.less
FileError: '/styles/vars.less' wasn't found. Tried - /styles/vars.less,D:\projects\ui\themes\default\styles\vars.less in D:\projects\ui\themes\default\style.less on line 1, column 1:
1 #import "/styles/vars.less";
2
Process finished with exit code 1
But if I change the path to something invalid:
Now I see "Cannot resolve file" as well as the unresolved variable. Is this a bug or something I'm doing wrong?
Here is the folder structure of the relevant files:
(root)/
├── styles/
│ ├── vars.less
├── themes/
│ ├── default/
│ └── style.less (the file with the error)

From list of directories, copy all subfolders to new location each with own folder per directory

I've searched around and can't seem to find a solution on my own so I'm asking for help!
I have a list of ~100 file locations/directories. They're located on the network and I need to grab them all and store them locally. I have some experience with VBA so I was going to try and use that (perhaps put the directories in a spread sheet and run a macro off that..)
When I store them locally I need to preserve the names of the directories they came from.
Any help would be MASSIVELY appreciated, automating this is becoming more and more necessary as I'm being sent more directories and a manual process will not scale well as this moves forward.
Any help at all, pointing me in a direction or offering advice is GREATLY appreciated.
Cheers
You can use the Copy-Item cmdlet in PowerShell combined with the -recurse and -container switches to copy and preserve folder structure! It's awesome for backing up a full network folder, and all sub-folders too!
Here is my Source directory.
C:\temp\stack>tree /F
Folder PATH listing
Volume serial number is 0000000B 9215:D0CB
C:.
├───Dest
└───Source
├───1
│ Archive.rar
│ File01.bmp
│
├───2
│ Archive.rar
│ File01.bmp
│
├───3
│ Archive.rar
│ File01.bmp
│
└───4
3.txt
Archive.rar
File01.bmp
Ham.txt
As you can see, I have some files and folders in Source with subfolders and subfiles in each. With this one simple PowerShell command though, I can move that whole structure easily into Dest.
copy-item -Path c:\temp\stack\source -Destination C:\temp\stack\Dest -Container -Recurse
Now I have that whole structure maintained in the Dest folder as well.
C:\temp\stack>tree /F
Folder PATH listing
Volume serial number is 000000DE 9215:D0CB
C:.
├───Dest
│ ├───1
│ │ Archive.rar
│ │ File01.bmp
│ │
│ ├───2
│ │ Archive.rar
│ │ File01.bmp
│ │
│ ├───3
│ │ Archive.rar
│ │ File01.bmp
│ │
│ └───4
│ 3.txt
│ Archive.rar
│ File01.bmp
│ Ham.txt
Copy-Item will work as mentioned. robocopy was also built for this exact purpose, and will run in cmd or Powershell. Run robocopy /? for usage info.
You probably want something like:
robocopy "Y:\Network\Source\Location" "C:\Local\Machine\Destination\Location" /E
/E Means to copy the directory and all subdirectories.

Correct cmake setup to include headers

I have a project structured like this:
─root
├──src
│ ├──main.cpp
│ └──CMakeLists.txt[2]
├──build
├──out
├──inc
├──dep
│ ├──log
│ │ ├──include
│ │ │ └──log.h
│ │ ├──src
│ │ │ └──log.cpp
│ │ └──CMakeLists.txt[4]
│ └──CMakeLists.txt[3]
└──CMakeLists.txt[1]
Under dep I have a logging library, which is an external git repository with his own CMakeLists.txt file.
The main CMakeLists.txt (marked as [1]) is:
cmake_minimum_required(VERSION 2.6)
set(APP_ROOT ${PROJECT_SOURCE_DIR})
add_subdirectory(dep)
add_subdirectory(src)
The CMakeLists.txt (marked as [2]) for the current project code is:
add_executable(app main.cpp)
target_link_libraries(app log)
include_directories("${APP_ROOT}/inc")
The CMakeLists.txt (marked as [3]) for the dependencies is:
add_subdirectory(log)
What I'm trying to do is to have the contents of the dep/log/include folder copied inside a new folder called inc/log, so that in main.cpp I can write something like #include <log/log.h>, but I don't understand how. I would like to avoid editing the CMakeLists.txt of the logger project.
My solution: in /dep/CMakeLists.txt I added
file(MAKE_DIRECTORY "${APP_ROOT}/inc/log")
file(COPY "log/include/" DESTINATION "${APP_ROOT}/inc/log")