Skip to content

Commit

Permalink
Added release workflow to auto-generate container (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonking3 authored Oct 4, 2023
1 parent a43c0fc commit 8f4d936
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 2 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
name: Release
on:
release:
types:
- created
workflow_dispatch:
inputs:
tag:
description: 'Image Tag'
required: true
type: string
default: 'latest'

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}/mdd


jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
submodules: recursive

- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
if: ${{ ! inputs.tag }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build and push Docker image
if: ${{ inputs.tag }}
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
file: Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.tag }}
labels: ${{ steps.meta.outputs.labels }}
30 changes: 30 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM --platform=linux/amd64 ubuntu:22.04

ARG build_date=unspecified

# workspace location
ARG WORKSPACE
ENV WORKSPACE ${WORKSPACE:-/ansible}
ENV ANSIBLE_COLLECTIONS_PATH /

COPY requirements.txt /tmp/requirements.txt
COPY requirements.yml /tmp/requirements.yml
COPY . /tmp/ansible-mdd

USER root
RUN mkdir /root/.ssh && bash -c 'echo -e "Host *\n KexAlgorithms +diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1" > /root/.ssh/config'
RUN mkdir /ansible_collections && chmod 777 /ansible_collections
RUN apt-get update && \
apt-get install -y python3.10 python3-pip sshpass git && \
pip3 install --upgrade --no-cache-dir setuptools pip && \
echo "===> Installing PIP Requirements <===" && \
pip3 install --no-cache -r /tmp/requirements.txt && \
echo "===> Installing Ansible Collections <===" && \
rm -rf /var/lib/apt/lists/* && \
ansible-galaxy collection install -r /tmp/requirements.yml

ENV ANSIBLE_HOST_KEY_CHECKING=false \
ANSIBLE_RETRY_FILES_ENABLED=false \
ANSIBLE_SSH_PIPELINING=true

WORKDIR ${WORKSPACE}
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ test: clean build $(VENV) $(TARBALL_NAME) ## Run Sanity Tests
$(VENV_BIN)/pip uninstall -y ansible-base
$(VENV_BIN)/pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
cd ./ansible_collections/ciscops/mdd && ../../../$(VENV_BIN)/ansible-test sanity --docker -v --color
$(RM) $(TARBALL_NAME)
$(RM) -r ./ansible_collections
$(RM) -r ./venv

clean: ## Clean
$(RM) $(TARBALL_NAME)
Expand Down
7 changes: 5 additions & 2 deletions galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace: ciscops
name: mdd

# The version of the collection. Must be compatible with semantic versioning
version: 1.2.9
version: 1.2.10

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down Expand Up @@ -72,4 +72,7 @@ build_ignore:
- '.env'
- '.github'
- 'tests/output/'
- 'ansible_collections/'
- 'ansible_collections'
- 'Dockerfile'
- 'requirements.txt'
- 'requirements.yml'
16 changes: 16 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ansible==8.4.0
virl2_client==2.6.0
netaddr
pynetbox
jsonschema
ipaddress
paramiko
genie
pyats
jmespath
passlib
botocore
boto3
nso-oc==2.79.4
networkx
scipy
9 changes: 9 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
collections:
- name: https://github.com/ciscodevnet/ansible-cml.git
type: git
- source: /tmp/ansible-mdd
type: dir
- name: https://github.com/model-driven-devops/ansible-nso.git
type: git
- name: amazon.aws
source: https://galaxy.ansible.com

0 comments on commit 8f4d936

Please sign in to comment.