diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml index 37e04ba..4de2a96 100644 --- a/.azure-pipelines.yml +++ b/.azure-pipelines.yml @@ -73,10 +73,7 @@ stages: cd test-$(command) echo "" > NuGet.config - cat NuGet.config - version=$(cat $(Build.ArtifactStagingDirectory)/nuget/version.txt) - echo "Using version $version" # Install the dotnet-$(command) tool dotnet tool install --global dotnet-$(command) --version $version --add-source $(Build.ArtifactStagingDirectory)/nuget @@ -88,7 +85,62 @@ stages: dotnet $(command) install dotnet $(command) -o $(Build.ArtifactStagingDirectory)/packages/$(container) workingDirectory: $(Pipeline.Workspace) + displayName: Run dotnet $(command) - task: PublishBuildArtifacts@1 inputs: pathToPublish: $(Build.ArtifactStagingDirectory)/packages/ artifactName: packages + + - job: molecule + pool: + vmImage: 'ubuntu-18.04' + steps: + - bash: | + set -e + export PATH=~/.local/bin/:$PATH + + pip3 install wheel + pip3 install --upgrade --user setuptools + pip3 install --user molecule + pip3 install --user docker-py + molecule --version + ansible --version + displayName: Install molecule + - task: DownloadBuildArtifacts@0 + displayName: Download Build Artifacts + inputs: + artifactName: nuget + downloadPath: $(Build.ArtifactStagingDirectory) + - bash: | + set -e + export PATH="$PATH:/$HOME/.dotnet/tools" + + cd self-contained-app + + echo "" > NuGet.config + version=$(cat $(Build.ArtifactStagingDirectory)/nuget/version.txt) + + # Install the dotnet-rpm and dotnet-deb tools + dotnet tool install --global dotnet-deb --version $version --add-source $(Build.ArtifactStagingDirectory)/nuget + dotnet tool install --global dotnet-rpm --version $version --add-source $(Build.ArtifactStagingDirectory)/nuget + + # Create .deb and .rpm packages + dotnet rpm install + dotnet rpm -o $(Build.SourcesDirectory)/molecule/self-contained/ + dotnet deb -o $(Build.SourcesDirectory)/molecule/self-contained/ + workingDirectory: $(Build.SourcesDirectory)/molecule/self-contained + displayName: Build self-contained-app + - bash: | + set -e + export PATH=~/.local/bin/:$PATH + + molecule test + workingDirectory: $(Build.SourcesDirectory)/molecule/self-contained + displayName: Run molecule tests for self-contained-app + - task: PublishTestResults@2 + inputs: + testResultsFormat: 'JUnit' + testResultsFiles: 'pytest.xml' + searchFolder: '$(Build.SourcesDirectory)/molecule/self-contained/molecule/default/' + condition: always() + displayName: Publish test results diff --git a/.gitignore b/.gitignore index 68f1105..803ebdc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ obj/ *.pkg *.zip *.tar.gz +__pycache__/ \ No newline at end of file diff --git a/Packaging.Targets/build/Packaging.Targets.targets b/Packaging.Targets/build/Packaging.Targets.targets index 3a42d5c..9e77ba1 100644 --- a/Packaging.Targets/build/Packaging.Targets.targets +++ b/Packaging.Targets/build/Packaging.Targets.targets @@ -39,7 +39,33 @@ $(PackageDescription) $(PackageProjectUrl) - + + + + + + + + @@ -87,21 +113,15 @@ - + - - + - - - - - + + diff --git a/molecule/self-contained/.yamllint b/molecule/self-contained/.yamllint new file mode 100644 index 0000000..3a2255e --- /dev/null +++ b/molecule/self-contained/.yamllint @@ -0,0 +1,13 @@ +extends: default + +rules: + braces: + max-spaces-inside: 1 + level: error + brackets: + max-spaces-inside: 1 + level: error + line-length: disable + # NOTE(retr0h): Templates no longer fail this lint rule. + # Uncomment if running old Molecule templates. + # truthy: disable diff --git a/molecule/self-contained/meta/main.yml b/molecule/self-contained/meta/main.yml new file mode 100644 index 0000000..ca5a444 --- /dev/null +++ b/molecule/self-contained/meta/main.yml @@ -0,0 +1,14 @@ +--- +galaxy_info: + author: Frederik Carlier + description: | + Ansible Role to deploy a self-contained app created with dotnet deb or dotnet rpm + to a machine. Used to test dotnet deb and dotnet rpm. + license: MIT + min_ansible_version: 1.2 + galaxy_tags: [] + platforms: + - name: Debian + - name: Ubuntu + - name: CentOS +dependencies: [] diff --git a/molecule/self-contained/molecule/default/Dockerfile.j2 b/molecule/self-contained/molecule/default/Dockerfile.j2 new file mode 100644 index 0000000..ed5fba0 --- /dev/null +++ b/molecule/self-contained/molecule/default/Dockerfile.j2 @@ -0,0 +1,18 @@ +# Molecule managed + +{% if item.registry is defined %} +FROM {{ item.registry.url }}/{{ item.image }} +{% else %} +FROM {{ item.image }} +{% endif %} + +# Patched for RHEL 8 support via +# https://github.com/ansible/molecule/issues/2348 +RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get install -y python sudo bash ca-certificates iproute2 && apt-get clean; \ + elif [ $(command -v dnf) ] && [ $(rpm -E %{rhel}) -eq 8 ]; then dnf makecache && dnf --assumeyes install python3 python3-devel python3-dnf python3-pip bash iproute sudo && dnf clean all; \ + elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install python sudo python-devel python*-dnf bash iproute && dnf clean all; \ + elif [ $(command -v yum) ]; then yum makecache fast && yum install -y python sudo yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ + elif [ $(command -v zypper) ]; then zypper refresh && zypper install -y python sudo bash python-xml iproute2 && zypper clean -a; \ + elif [ $(command -v apk) ]; then apk update && apk add --no-cache python sudo bash ca-certificates; \ + elif [ $(command -v xbps-install) ]; then xbps-install -Syu && xbps-install -y python sudo bash ca-certificates iproute2 && xbps-remove -O; fi + diff --git a/molecule/self-contained/molecule/default/molecule.yml b/molecule/self-contained/molecule/default/molecule.yml new file mode 100644 index 0000000..db89452 --- /dev/null +++ b/molecule/self-contained/molecule/default/molecule.yml @@ -0,0 +1,74 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: + name: yamllint +platforms: + # This list should be roughly kept in sync with the list of supported OSes described at + # https://github.com/dotnet/core/blob/master/release-notes/3.0/3.0-supported-os.md, + # and/or the list of OSes for which .NET Core builds packages, as seen at + # https://dotnet.microsoft.com/download/linux-package-manager/sdk-current + # There are no Docker images for RHEL, so we can't test that. + # Not sure about Linux Mint/Suse Enterprise Linux docker images, so they are skipped for now. + # + # OpenSUSE uses zypper as the package manager, but zypper doesn't seem to + # handle RPM boolean dependencies. Installing the rpm package will fail like + # this: + # + # > Problem: nothing provides (openssl-libs or libopenssl1_1 or libopenssl_1_0_0) >= needed by self-contained-app-1.0.0-0.x86_64 + # + # You can manually install the package using rpm -i {path_to_rpm}, though, but Ansible doesn't provide + # a good way to do that. + # + # - name: opensuse.15.0 + # image: opensuse/leap:15.0 + # - name: opensuse.15.1 + # image: opensuse/leap:15.1 + # - name: opensuse.15.2 + # image: opensuse/leap:15.2 + - name: centos.7 + image: centos:7 + - name: centos.8 + image: centos:8 + - name: ol.7 + image: oraclelinux:7 + - name: ol.8 + image: oraclelinux:8 + - name: fedora.30 + image: fedora:30 + - name: fedora.29 + image: fedora:29 + - name: debian.8 + image: debian:8 + - name: debian.9 + image: debian:9 + - name: debian.10 + image: debian:10 + - name: ubuntu.14.04 + image: ubuntu:14.04 + - name: ubuntu.16.04 + image: ubuntu:16.04 + - name: ubuntu.18.04 + image: ubuntu:18.04 + - name: ubuntu.19.10 + image: ubuntu:19.10 + +provisioner: + name: ansible + lint: + name: ansible-lint + inventory: + host_vars: + fedora.30: + # https://github.com/ansible/ansible/issues/54855 + ansible_python_interpreter: /usr/bin/python3 +scenario: + name: default +verifier: + name: testinfra + options: + junitxml: pytest.xml + lint: + name: flake8 diff --git a/molecule/self-contained/molecule/default/playbook.yml b/molecule/self-contained/molecule/default/playbook.yml new file mode 100644 index 0000000..b042d7c --- /dev/null +++ b/molecule/self-contained/molecule/default/playbook.yml @@ -0,0 +1,5 @@ +--- +- name: Converge + hosts: all + roles: + - role: self-contained diff --git a/molecule/self-contained/molecule/default/tests/test_default.py b/molecule/self-contained/molecule/default/tests/test_default.py new file mode 100644 index 0000000..7d230fe --- /dev/null +++ b/molecule/self-contained/molecule/default/tests/test_default.py @@ -0,0 +1,10 @@ +import os + +import testinfra.utils.ansible_runner + +testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( + os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') + + +def test_package_is_runnable(host): + host.run_test("/usr/share/self-contained-app/self-contained-app") diff --git a/molecule/self-contained/self-contained-app/Program.cs b/molecule/self-contained/self-contained-app/Program.cs new file mode 100644 index 0000000..9bd71fd --- /dev/null +++ b/molecule/self-contained/self-contained-app/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace self_contained_app +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/molecule/self-contained/self-contained-app/self-contained-app.csproj b/molecule/self-contained/self-contained-app/self-contained-app.csproj new file mode 100644 index 0000000..f0040d8 --- /dev/null +++ b/molecule/self-contained/self-contained-app/self-contained-app.csproj @@ -0,0 +1,10 @@ + + + + Exe + netcoreapp3.0 + self_contained_app + linux-x64 + + + diff --git a/molecule/self-contained/tasks/deb.yml b/molecule/self-contained/tasks/deb.yml new file mode 100644 index 0000000..52a058d --- /dev/null +++ b/molecule/self-contained/tasks/deb.yml @@ -0,0 +1,10 @@ +--- +- name: Copy self-contained app to guest + copy: + src: "{{ role_path }}/self-contained-app.1.0.0.linux-x64.deb" + dest: /home/self-contained-app.1.0.0.linux-x64.deb + +- name: Install self-contained app + become: true + apt: + deb: /home/self-contained-app.1.0.0.linux-x64.deb diff --git a/molecule/self-contained/tasks/main.yml b/molecule/self-contained/tasks/main.yml new file mode 100644 index 0000000..e73c76d --- /dev/null +++ b/molecule/self-contained/tasks/main.yml @@ -0,0 +1,11 @@ +--- +- include_tasks: deb.yml + when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' + +- include_tasks: rpm.yml + when: > + ansible_distribution == 'CentOS' + or ansible_distribution == 'RedHat' + or ansible_distribution == 'OracleLinux' + or ansible_distribution == 'Fedora' + or ansible_distribution == 'openSUSE Leap' diff --git a/molecule/self-contained/tasks/rpm.yml b/molecule/self-contained/tasks/rpm.yml new file mode 100644 index 0000000..e156e31 --- /dev/null +++ b/molecule/self-contained/tasks/rpm.yml @@ -0,0 +1,14 @@ +--- +- name: Copy self-contained app to guest + copy: + src: "{{ role_path }}/self-contained-app.1.0.0.linux-x64.rpm" + dest: /home/self-contained-app.1.0.0.linux-x64.rpm + +- name: Install self-contained app + become: true + yum: + name: /home/self-contained-app.1.0.0.linux-x64.rpm + state: present + # We sign RPM packages with a PGP key, but don't export the PGP key yet. + # Skip GPG checks for now. + disable_gpg_check: true