Add Molecule test for self-contained app

This commit is contained in:
Frederik Carlier
2019-11-22 16:04:47 +01:00
parent f645ef5d15
commit b831ea3540
13 changed files with 242 additions and 3 deletions

View File

@@ -73,10 +73,7 @@ stages:
cd test-$(command)
echo "<configuration><packageSources><add key='local' value='$(Build.ArtifactStagingDirectory)/nuget' /></packageSources></configuration>" > 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 "<configuration><packageSources><add key='local' value='$(Build.ArtifactStagingDirectory)/nuget' /></packageSources></configuration>" > 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

1
.gitignore vendored
View File

@@ -11,3 +11,4 @@ obj/
*.pkg
*.zip
*.tar.gz
__pycache__/

View File

@@ -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

View File

@@ -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: []

View File

@@ -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

View File

@@ -0,0 +1,69 @@
---
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
scenario:
name: default
verifier:
name: testinfra
options:
junitxml: pytest.xml
lint:
name: flake8

View File

@@ -0,0 +1,5 @@
---
- name: Converge
hosts: all
roles:
- role: self-contained

View File

@@ -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")

View File

@@ -0,0 +1,12 @@
using System;
namespace self_contained_app
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View File

@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RootNamespace>self_contained_app</RootNamespace>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
</PropertyGroup>
</Project>

View File

@@ -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

View File

@@ -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'

View File

@@ -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