Skip to content

Commit

Permalink
2024 updates
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Buchleitner <[email protected]>
  • Loading branch information
mabunixda committed Nov 5, 2024
2 parents 1e16f62 + 269113b commit 130fbbe
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 176 deletions.
157 changes: 0 additions & 157 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,157 +0,0 @@
name: Infralovers Container Build

# ref: github.com/infralovers/github/workflow-templates/container.yml

on:
push:
branches: [ 'main', 'v2', 'v3' ]
pull_request:
branches: [ 'main', 'v2', 'v3' ]

jobs:
prebuild:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.semrel.outputs.version }}
steps:
- uses: actions/checkout@v3

- name: Check pre-commit presence
id: precommit_exists
uses: andstor/file-existence-action@v1
with:
files: ".pre-commit-config.yaml"

- uses: actions/setup-python@v3
if: steps.precommit_exists.outputs.files_exists == 'true'

- uses: pre-commit/[email protected]
if: steps.precommit_exists.outputs.files_exists == 'true'

- uses: go-semantic-release/action@v1
if: github.event_name != 'pull_request'
id: semrel
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
prepend: true
dry: true

build:
runs-on: ubuntu-latest
needs: [ prebuild ]
steps:
- uses: actions/checkout@v2

- name: Prepare tagging
id: prep
run: |
CURRENT_VERSION="${{ needs.prebuild.outputs.version }}"
IMAGE_PREFIX="v1"
IMAGE_NAME=$(basename ${{ github.repository }})
IMAGE_REPO=${{ github.repository_owner }}
git fetch --tags
LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/v//')
if [ "$GITHUB_REF_NAME" == "v2" ] || [ "$GITHUB_BASE_REF" == "v2" ]; then
IMAGE_PREFIX="v2"
if [ "$GITHUB_REF_NAME" == "v2" ]; then
CURRENT_VERSION=$LATEST_TAG
fi
fi
if [ "$GITHUB_REF_NAME" == "v3" ] || [ "$GITHUB_BASE_REF" == "v3" ]; then
IMAGE_PREFIX="v3"
if [ "$GITHUB_REF_NAME" == "v3" ]; then
CURRENT_VERSION=$LATEST_TAG
fi
fi
if [[ -n "${{ secrets.IMAGE_NAME }}" ]]; then
IMAGE_NAME="${{ secrets.IMAGE_NAME }}"
fi
if [[ -n "${{ secrets.IMAGE_REPO }}" ]]; then
IMAGE_REPO="${{ secrets.IMAGE_REPO }}"
fi
QUAY_IMAGE="quay.io/$IMAGE_REPO/$IMAGE_NAME"
GHCR_IMAGE="ghcr.io/${{ github.repository }}"
VERSION="${IMAGE_PREFIX}-dev"
if [[ '${CURRENT_VERSION}' != '' ]]; then
VERSION="${IMAGE_PREFIX}-${CURRENT_VERSION}"
fi
if [ "${{ github.event_name }}" = "schedule" ]; then
VERSION="${IMAGE_PREFIX}-nightly"
fi
TAGS="${QUAY_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION}"
if [[ "${CURRENT_VERSION}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
TAGS="$TAGS,${QUAY_IMAGE}:${IMAGE_PREFIX},${GHCR_IMAGE}:${IMAGE_PREFIX}"
fi
echo "settings tag ${TAGS}"
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "next_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'arm64,amd64'

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to Quay
if: steps.prep.outputs.next_version != ''
uses: docker/login-action@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USER }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Login to GitHub Container Registry
if: steps.prep.outputs.next_version != ''
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.BOT_ACCESS_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' && steps.prep.outputs.next_version != '' }}
tags: ${{ steps.prep.outputs.tags }}
platforms: 'arm64,amd64'

release:
needs: [ prebuild, build ]
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v2

- uses: go-semantic-release/action@v1
if: needs.prebuild.outputs.version != ''
id: generate_changelog
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
prepend: true
changelog-file: CHANGELOG.md

- name: Update changelog
uses: stefanzweifel/git-auto-commit-action@v4
if: steps.generate_changelog.outputs.version != ''
with:
commit_message: 'chore(ci): commit changes from go-semantic-release'
file_pattern: CHANGELOG.md
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
<<<<<<< HEAD
=======
## 1.0.2 (2024-05-08)

#### Bug Fixes

* Change workflow (#7) (e20e91fd)

#### Chores

* **ci:** commit changes from go-semantic-release (4ae48c04)



## 1.0.1 (2023-03-20)

#### Bug Fixes

* update version match (#2) (39a9c268)

#### Chores

* **ci:** commit changes from go-semantic-release (568992f4)


>>>>>>> updates-2024
## 1.0.0 (2023-03-20)

#### Feature
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use an official Python runtime as a parent image
FROM python:3.7-slim
FROM python:3.12-slim

ENV NAME World

Expand All @@ -16,7 +16,7 @@ RUN pip install --trusted-host pypi.python.org -r /app/requirements.txt
EXPOSE 80

# Define environment variable
ENV NAME World
ENV NAME=World

# Run app.py when the container launches
CMD ["python", "app.py"]
21 changes: 13 additions & 8 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
import socket
import datetime
import configparser
from datetime import datetime

app = Flask(__name__)
configParser = configparser.ConfigParser()

@app.route("/")
def hello():

now = datetime.datetime.now()
html = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Domainname: </b> {domainname}<br/>" \
"<b>Port: </b> {port}<br/>" \
"<b>Config Sections: </b> {sections}<br/>" \
"<b>Current Date:</b> {currentdate}<br/>"
return html.format(name=os.getenv("NAME", "world"),
now = datetime.now()
html = """
<h3>Hello {name}!</h3>
<b>Hostname:</b> {hostname}<br/>
<b>Current Date:</b> {currentdate}<br/>
<b>Domainname: </b> {domainname}<br/>
<b>Port: </b> {port}<br/>
<b>Config Sections: </b> {sections}<br/>
<b>Current Date:</b> {currentdate}<br/>
"""
return html.format(name=os.getenv("NAME", "world"),
hostname=socket.gethostname(),
currentdate=str(now),
domainname=configParser.get('app', 'domainname'),
port=configParser.get('app','port'),
sections=', '.join(configParser.sections()),
Expand Down
2 changes: 1 addition & 1 deletion src/etc/config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[app]
domainname=commandemy.training
domainname=infralovers.academy
port=80

[default]
Expand Down
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Flask
Flask>=3
11 changes: 4 additions & 7 deletions training-prerequisites.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ Have the images in a registry available for attendees

$ git clone https://github.com/infralovers/training-flask-app
$ cd training-flask-app/
$ $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin
$ echo $CR_PAT | docker login ghcr.io -u USERNAME --password-stdin

$ docker build -t friendlyhello .
$ docker tag friendlyhello ghcr.io/infralovers/training-flask-app:v1
$ docker build -t ghcr.io/infralovers/training-flask-app:v1 .
$ docker push ghcr.io/infralovers/training-flask-app:v1

$ git switch v2
$ docker build -t training-flask-app:v2 .
$ docker tag training-flask-app:v2 ghcr.io/infralovers/training-flask-app:v2
$ docker build -t ghcr.io/infralovers/training-flask-app:v2 .
$ docker push ghcr.io/infralovers/training-flask-app:v2

$ git switch v3
$ docker build -t training-flask-app:v3 .
$ docker tag training-flask-app:v3 ghcr.io/infralovers/training-flask-app:v3
$ docker build -t ghcr.io/infralovers/training-flask-app:v3 .
$ docker push ghcr.io/infralovers/training-flask-app:v3
```

0 comments on commit 130fbbe

Please sign in to comment.