Skip to content

Commit

Permalink
Merge pull request #6 from ministryofjustice/docker-repo
Browse files Browse the repository at this point in the history
Docker repo
  • Loading branch information
Stephen James authored Dec 6, 2023
2 parents 18e1127 + 96a9334 commit c56c107
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 10 deletions.
4 changes: 1 addition & 3 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Add a team or username to this file
# Example:
# * @ministryofjustice/operations-engineering
* @ministryofjustice/nvvs-devops-admins
41 changes: 41 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: release

on:
push:
tags: ['v*.*.*'] # only a valid semver tag

env:
REGISTRY: ghcr.io
IMAGE_NAME: '${{ github.repository_owner }}/nvvs/juniper-mist-integration/app'

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

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Docker Login
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
file: docker/Dockerfile
push: true
tags: ${{ steps.metadata.outputs.tags }}
labels: ${{ steps.metadata.outputs.labels }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ env/
terraform.tfstate

data_src/**.csv
./idea/*
.idea
**/__pycache__/
65 changes: 59 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,97 @@
#!make
.DEFAULT_GOAL := help
SHELL := '/bin/bash'
REGISTRY := ghcr.io
GITHUB_OWNER := $$(git config remote.origin.url | cut -d : -f 2 | cut -d / -f 1)
GITHUB_REPO := $$(basename `git rev-parse --show-toplevel`)
TEAM_NAME := "nvvs"
CONTAINER_NAME := "app"
NAME := ${GITHUB_OWNER}/${TEAM_NAME}/${GITHUB_REPO}/${CONTAINER_NAME}
TAG := $$(git log -1 --pretty=%h)
IMG := ${NAME}:${TAG}
LATEST := ${NAME}:latest

CURRENT_VERSION := $$(git describe --abbrev=0)
CURRENT_NUMBER := $$(echo $(CURRENT_VERSION) | cut -d "v" -f 2)

ifeq ($(SEMVAR),patch)
NEXT_NUMBER := $$(./semver/increment_version.sh -p $(CURRENT_NUMBER))
else ifeq ($(SEMVAR),minor)
NEXT_NUMBER := $$(./semver/increment_version.sh -m $(CURRENT_NUMBER))
else ifeq ($(SEMVAR),major)
NEXT_NUMBER := $$(./semver/increment_version.sh -M $(CURRENT_NUMBER))
endif

NEXT_VERSION := "v$(NEXT_NUMBER)"

.PHONY: debug
debug: ## debug
@echo $(NEXT_NUMBER)

.PHONY: current_version
current_version: ## Get current version eg v3.4.1
@echo $(CURRENT_VERSION)
@echo $(CURRENT_NUMBER)

.PHONY: preview_version
preview_version: ## increment version eg v3.4.1 > v3.5.0. Use SEMVAR=[ patch | minor | major ]
ifeq ($(filter $(SEMVAR), patch minor major),)
$(error invalid `SEMVAR` value)
endif
@echo "CURRENT_VERSION := $(CURRENT_VERSION)"
@echo "$(SEMVAR) := $(NEXT_VERSION)"

.PHONY: preview_name
preview_name: ## view container name
@echo "NAME := $(NAME)"

.PHONY: tag
tag: ## Tag branch in git repo with next version number. Use SEMVAR=[ patch | minor | major ]
ifeq ($(filter $(SEMVAR), patch minor major),)
$(error invalid `SEMVAR` value)
endif
@echo "tagging with $(NEXT_VERSION)"
@git tag -a "$(NEXT_VERSION)" -m "Bump from $(CURRENT_VERSION) to $(NEXT_VERSION)"
@git push origin main --follow-tags

.PHONY: build
build: ## Build the docker container
docker build -t juniper-mist -f docker/Dockerfile .
docker build --tag ${IMG} -f docker/Dockerfile .
docker tag ${IMG} ${LATEST}

.PHONO: create-dir
make create-dir: ## Creates a directory for end user to put CSV file into
mkdir data_src;
echo "Please put csv file into data_src then run 'make-prod'";
echo "Please put csv file into data_src then run 'make run-prod'";

.PHONY: run-prod
run-prod: ## Run the python script only mounting the host for csv-file. Format: MIST_API_TOKEN=foo ORG_ID=bar make run-prod
docker run -v $(shell pwd)/data_src:/data_src \
-e MIST_API_TOKEN=$$MIST_API_TOKEN \
-e ORG_ID=$$ORG_ID \
juniper-mist
$(NAME)

.PHONY: run-dev
run-dev: ## Run the python script while mounting the host. This enables using the latest local src code without needing to wait for a container build. Format: MIST_API_TOKEN=foo ORG_ID=bar make run-dev
docker run -v $(shell pwd)/src:/app/src \
-v $(shell pwd)/data_src:/data_src \
-e MIST_API_TOKEN=$$MIST_API_TOKEN \
-e ORG_ID=$$ORG_ID \
juniper-mist
$(NAME)

.PHONY: tests
tests: ## Run unit tests for the python app
docker run -v $(shell pwd)/src:/app/src \
-v $(shell pwd)/test:/app/test \
-e RUN_UNIT_TESTS=True juniper-mist
-e RUN_UNIT_TESTS=True $(NAME)

.PHONY: shell
shell: ## Make interactive docker container
docker run -it --entrypoint /bin/bash \
-v $(shell pwd)/src:/app/src \
-v $(shell pwd)/test:/app/test \
-v $(shell pwd)/data_src:/data_src \
-e RUN_UNIT_TESTS=True juniper-mist
-e RUN_UNIT_TESTS=True $(NAME)

help:
@grep -h -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
22 changes: 22 additions & 0 deletions semver/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2014 Fritz Mahnke

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22 changes: 22 additions & 0 deletions semver/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# bash-semver

Increment semantic versioning strings in shell scripts.

```shell
$ ./increment_version.sh
usage: increment_version.sh [-Mmp] major.minor.patch

$ ./increment_version.sh -p 0.0.0
0.0.1

$ ./increment_version.sh -m 0.0.3
0.1.0

$ ./increment_version.sh -M 1.1.15
2.0.0

$ ./increment_version.sh -Mmp 2.3.4
3.1.1
```

Sourced from https://github.com/fmahnke/shell-semver
53 changes: 53 additions & 0 deletions semver/increment_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash

# Increment a version string using Semantic Versioning (SemVer) terminology.

# Parse command line options.

while getopts ":Mmp" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
esac
done

shift $(($OPTIND - 1))

version=$1

# Build array from version string.

a=( ${version//./ } )

# If version string is missing or has the wrong number of members, show usage message.

if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
exit 1
fi

# Increment version numbers as requested.

if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi

if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi

if [ ! -z $patch ]
then
((a[2]++))
fi

echo "${a[0]}.${a[1]}.${a[2]}"

0 comments on commit c56c107

Please sign in to comment.