Skip to content

Commit

Permalink
Init container debug
Browse files Browse the repository at this point in the history
  • Loading branch information
lrakai committed Oct 13, 2023
1 parent be800ee commit e0c615d
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
**/__pycache__
**/.venv
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
42 changes: 42 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Build and Push Docker Image

on:
push

env:
IMAGE_NAME: ghcr.io/cloudacademy/google-vcf

permissions:
contents: read
packages: write

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set outputs
id: vars
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GHCR
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ env.IMAGE_NAME }}:${{ github.ref_name }},${{ env.IMAGE_NAME }}:${{ github.ref_name }}-${{ steps.vars.outputs.sha_short }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
venv/
__pycache__
requirements.txt
.config.env
21 changes: 18 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,24 @@
"console": "integratedTerminal",
"env": {
// VCF account
"CREDENTIAL_KEY" : "INSERT_CREDENTIAL_KEY",
"CREDENTIAL_ID" : "INSERT_CREDENTIAL_ID",
"PROJECT_ID" : "INSERT_PROJECT_ID"
"CREDENTIAL_KEY": "INSERT_CREDENTIAL_KEY",
"CREDENTIAL_ID": "INSERT_CREDENTIAL_ID",
"PROJECT_ID": "INSERT_PROJECT_ID"
}
},
{
"name": "Docker: Python - General",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"python": {
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/app"
}
],
"projectType": "general"
}
}
]
Expand Down
26 changes: 26 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "docker-build",
"label": "docker-build",
"platform": "python",
"dockerBuild": {
"tag": "gcpvcfenv:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build"
],
"python": {
"file": "src/entry.py"
}
}
]
}
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.9-slim

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1

# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

# Install dev dependencies
RUN python -m pip install --upgrade python-dotenv==1.0.0
# Install pip requirements
COPY requirements.txt .
RUN python -m pip install -r requirements.txt

WORKDIR /app
COPY . /app
# move config.env to .env if .config.env exists but continue if it doesn't
RUN test -f .config.env && mv .config.env .env || true

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser

# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
CMD ["python", "src/entry.py"]
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-api-python-client
21 changes: 21 additions & 0 deletions src/entry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from dotenv import load_dotenv
load_dotenv()

import time
from config import EVENT_CONFIG
from vcf import handler


def timed_handler(event, context):
start = time.time()
result = handler(event, context)
end = time.time()
print(end - start)
return result

def entry():
result = timed_handler(EVENT_CONFIG, None)
print(result)

if __name__ == "__main__":
entry()

0 comments on commit e0c615d

Please sign in to comment.