Skip to content

Commit

Permalink
Added workflow file for publishing Acorn
Browse files Browse the repository at this point in the history
  • Loading branch information
aashimodi14 committed Oct 23, 2023
1 parent 27521df commit 58b9121
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 96 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Publish Acorn image
on:
workflow_dispatch:
push:
tags:
- "v[0-9]*"

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: acorn-io/actions-setup@v2
with:
acorn-version: "main"
- name: Login to GHCR
uses: acorn-io/actions-login@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Publish with signature
run: |
TAG=${GITHUB_REF#refs/*/}
acorn build --platform linux/amd64 --platform linux/arm64 --push -t ghcr.io/infracloudio/flask-acorn:${TAG} .
4 changes: 4 additions & 0 deletions Acornfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
name: "Flask Sample Acorn"
description: "Acorn running a sample Flask app"
readme: "./README.md"

containers: {
web: {
build: {
Expand Down
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM --platform=$BUILDPLATFORM python:3.10-alpine AS builder

ENV FLASK_APP=flaskr
ENV FLASK_RUN_HOST 0.0.0.0

COPY . /app

WORKDIR /app

#COPY requirements.txt /app
#RUN --mount=type=cache,target=/root/.cache/pip \
#pip3 install -r requirements.txt
RUN pip install -e ./
COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip \
pip3 install -r requirements.txt

RUN flask init-db

Expand Down
103 changes: 21 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,34 @@
# Flaskr
======

The basic blog app built in the Flask `tutorial`
The basic blog app built in the official Flask [tutorial](https://flask.palletsprojects.com/tutorial/). This sample application is a basic CRUD application to get started with Flask.

tutorial: https://flask.palletsprojects.com/tutorial/

## Deploy the Flask App

[_Acornfile_](.Acornfile)
```
containers: {
web: {
build: {
context: "."
target: "builder"
}
env: {
if args.dev {
"FLASK_DEBUG": "1"
}
}
if args.dev { dirs: "/app": "./" }
ports: publish: "5000/http"
}
}
```
You can deploy the sample Flask app on the Acorn SaaS Platform with following simple steps.

## Deploy with Acorn
1. Login into the [Acorn SaaS Platform](https://beta.acorn.io/) using the Github Sign-In option with your Github user.
2. Select the "Create Acorn" option.
3. Choose the source for deploying your Acorns
* Select "From Acorn Image" to deploy the sample Flask Application and select its Image
* Provide any random name such as `flask-app` and keeping Project's default Region, type in the below Acorn image and choose Create
```bash
ghcr.io/infracloudio/flask-acorn:v3.0.0-0
```
4. Now the sample App is provisioned on Acorn SaaS Platform and is available for 2hrs. Upgrade to pro account to keep it running longer.
5. Once the Acorn is running, you can access it by clicking the Endpoint or the redirect link.

Make sure to [_Install Acorn_](https://docs.acorn.io/installation/installing) before running acorns.
## Acorn Flask App Details

Clone this repo to get started and run below command to deploy this project
The Acorn Dashboard is integrated with multiple features such as Events, Logs, Details and accessing the Shell of the Application. Details include the CPU, Memory, Network, Latency, Requests and Errors for the Application.

```bash
acorn run .
```

Alternatively, you can directly run using the image like below

```bash
acorn run ghcr.io/infracloudio/flask-acorn:v0.0.1

```

## Explaining the Acornfile


* `containers` section: describes the set of containers your Acorn app consists of. Note: app are custom names of your containers
* `app` - Our Python Flask App
* `build`: build from Dockerfile that we created
* `env`: environment variables, statically defined, referencing a secret or referencing an Acorn argument
* `ports`: using the publish type, we expose the app inside the cluster but also outside of it using an auto-generated ingress resource
* `dirs`: Directories to mount into the container filesystem
* `dirs: "/app": "./"`: Mount the current directory to the /app dir, which is where the code resides inside the container as per the Dockerfile. This is to enable hot-reloading of code.


## Run your Application

To start your Acorn app just run:

```bash
acorn run -n flask-app .
```
The `-n flask-app` gives this app a specific name so that the rest of the steps can refer to it. If you omit `-n`, a random two-word name will be generated.

## Access your app

Due to the configuration `ports: publish: "8000/http"` under `containers.app`, our web app will be exposed outside of our Kubernetes cluster using the cluster's ingress controller. Checkout the running apps via

```bash
acorn apps
```

```bash
$ acorn apps
NAME IMAGE COMMIT CREATED ENDPOINTS MESSAGE
flask-app 0ed9a2b95c69 114c50666ed9 3m22s ago http://web-flask-app-98d916c5.local.oss-acorn.io OK

```

## Development Mode

In development mode, Acorn will watch the local directory for changes and synchronize them to the running Acorn app. In general, changes to the Acornfile are directly synchronized, e.g. adding environment variables, etc. Depending on the change, the deployed containers will be recreated.

```bash
acorn dev -n flask-app
```

The lines `if args.dev { dirs: "/app": "./" }` enable hot-reloading of code by mounting the current local directory into the app container.

You will see the change applied when you reload the application's page in your browser.
Explore various available options by clicking the Menu option on your Acorn App.

For more details on using the Acorn Dashboard, check this link - [https://beta-docs.acorn.io/getting-started#exploring-the-acorn-dashboard](https://beta-docs.acorn.io/getting-started#exploring-the-acorn-dashboard)

## What next?
After deploying you can edit the Acorn Application or remove it if no longer needed.

1. Click the Edit option to edit your Acorn's Image. Toggle the Advanced Options switch for additional edit options.
2. Remove the Acorn by selecting the Remove option from your Acorn dashboard.
9 changes: 0 additions & 9 deletions compose.yml

This file was deleted.

2 changes: 1 addition & 1 deletion flaskr/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ <h1><a href="{{ url_for('index') }}">Flaskr</a></h1>
<div class="flash">{{ message }}</div>
{% endfor %}
{% block content %}{% endblock %}
</section>
</section>

0 comments on commit 58b9121

Please sign in to comment.