Skip to content

Commit 9838030

Browse files
authored
Merge pull request #59 from PerfectThymeTech/marvinbuss/docker
Add Container
2 parents 05d4e20 + e751774 commit 9838030

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Docker Template
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
default: "dev"
10+
description: "Specifies the environment of the deployment."
11+
working_directory:
12+
required: false
13+
type: string
14+
default: ./code/function
15+
description: "Specifies the uri of the container registry."
16+
registry_uri:
17+
required: false
18+
type: string
19+
default: ghcr.io
20+
description: "Specifies the uri of the container registry."
21+
image_name:
22+
required: true
23+
type: string
24+
description: "Specifies the name of the image."
25+
secrets:
26+
USER_NAME:
27+
required: true
28+
description: "Specifies the user name for the container registry."
29+
PASSWORD:
30+
required: true
31+
description: "Specifies the password for the container registry."
32+
33+
jobs:
34+
deployment:
35+
name: Container Build & Push
36+
runs-on: ubuntu-latest
37+
continue-on-error: false
38+
environment: ${{ inputs.environment }}
39+
40+
steps:
41+
# Check Out Repository
42+
- name: Check Out Repository
43+
id: checkout_repository
44+
uses: actions/checkout@v4
45+
46+
# Install cosign
47+
- name: Install cosign
48+
uses: sigstore/cosign-installer@v3.1.2
49+
id: install_cosign
50+
if: github.event_name != 'pull_request'
51+
with:
52+
cosign-release: 'v2.2.0'
53+
54+
# Install QEMU
55+
- name: Set up QEMU
56+
id: install_qemu
57+
uses: docker/setup-qemu-action@v3
58+
59+
# Install BuildKit
60+
- name: Install Buildx
61+
id: install_buildx
62+
uses: docker/setup-buildx-action@v3.0.0
63+
64+
# Login Container Registry
65+
- name: Login Container Registry
66+
uses: docker/login-action@v3.0.0
67+
id: registry_login
68+
if: github.event_name != 'pull_request'
69+
with:
70+
registry: ${{ inputs.registry_uri }}
71+
username: ${{ secrets.USER_NAME }}
72+
password: ${{ secrets.PASSWORD }}
73+
74+
# Extract Metadata (tags, labels)
75+
- name: Extract Metadata
76+
id: metadata
77+
uses: docker/metadata-action@v5.0.0
78+
with:
79+
context: workflow
80+
images: |
81+
${{ inputs.registry_uri }}/${{ inputs.image_name }}
82+
tags: |
83+
type=ref,event=branch
84+
type=ref,event=pr
85+
type=semver,pattern={{version}}
86+
type=semver,pattern={{major}}.{{minor}}
87+
88+
# Build and Push Docker Image with Buildx
89+
- name: Build and push Docker image
90+
id: build_push
91+
uses: docker/build-push-action@v5.0.0
92+
with:
93+
context: ${{ inputs.working_directory }}
94+
file: ${{ inputs.working_directory }}/Dockerfile
95+
push: ${{ github.event_name != 'pull_request' }}
96+
tags: ${{ steps.metadata.outputs.tags }}
97+
labels: ${{ steps.metadata.outputs.labels }}
98+
cache-from: type=gha
99+
cache-to: type=gha,mode=max
100+
101+
# Sign container image
102+
# This step uses the identity token to provision an ephemeral certificate against the sigstore community Fulcio instance.
103+
- name: Sign container image
104+
id: sign
105+
if: ${{ github.event_name != 'pull_request' }}
106+
run: |
107+
echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}
108+
env:
109+
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
110+
TAGS: ${{ steps.metadata.outputs.tags }}
111+
DIGEST: ${{ steps.build_push.outputs.digest }}

.github/workflows/functionApp.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@ jobs:
2222
python_version: "3.10"
2323
function_directory: "./code/function"
2424

25+
function_container:
26+
uses: ./.github/workflows/_containerTemplate.yml
27+
name: "Function App Container"
28+
needs: [function_test]
29+
with:
30+
environment: "dev"
31+
working_directory: "./code/function"
32+
registry_uri: "ghcr.io"
33+
image_name: "AzureFunctionPython"
34+
secrets:
35+
USER_NAME: ${{ github.actor }}
36+
PASSWORD: ${{ secrets.GITHUB_TOKEN }}
37+
2538
function_deploy:
2639
uses: ./.github/workflows/_functionAppDeployTemplate.yml
2740
name: "Function App Deploy"

code/function/.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
local.settings.json

code/function/Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To enable ssh & remote debugging on app service change the base image to the one below
2+
# FROM mcr.microsoft.com/azure-functions/python:4-python3.7-appservice
3+
FROM mcr.microsoft.com/azure-functions/python:4-python3.11
4+
5+
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
6+
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
7+
8+
COPY requirements.txt /
9+
RUN pip install -r /requirements.txt
10+
11+
COPY . /home/site/wwwroot

0 commit comments

Comments
 (0)