Skip to content

Commit

Permalink
1st commit
Browse files Browse the repository at this point in the history
  • Loading branch information
takara9 committed May 20, 2024
0 parents commit ff1f2b5
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Include any files or directories that you don't want to be copied to your
# container here (e.g., local build artifacts, temporary files, etc.).
#
# For more help, visit the .dockerignore file reference guide at
# https://docs.docker.com/engine/reference/builder/#dockerignore-file

**/.DS_Store
**/__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
67 changes: 67 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Branch を Push したらイメージをビルドする

on:
push:
branches:
- '*' # matches every branch that doesn't contain a '/'
- '*/*' # matches every branch containing a single '/'
- '**' # matches every branch
- '!main' # excludes main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-test-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

#- name: Set up QEMU
# uses: docker/setup-qemu-action@v3
#- name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Build a image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
#platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}

- name: Start a container from the image
run: |
docker images
docker run -d --name test -p 9100:9100 ${{ steps.meta.outputs.tags }}
docker ps
- name: Test the container
run: |
sleep 5
docker ps
curl --silent --retry 3 --include http://127.0.0.1:9100/ping | grep "200 OK"
[ $? -ne 0 ] && (echo "error"; exit 1)
exit 0
50 changes: 50 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: タグを付与してリリースすると、イメージを作成する

on:
release:
types: [published]

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

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

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

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

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

- name: Build and push Docker image
id: push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
platforms: linux/amd64,linux/arm64
labels: ${{ steps.meta.outputs.labels }}

19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# syntax=docker/dockerfile:1
FROM ubuntu:22.04

# 依存するモジュールをインストール
RUN apt-get update && apt-get install -y python3 python3-pip
RUN pip install flask

# アプリケーションのインストール
RUN mkdir /app
WORKDIR /app
USER 65534:65534
COPY --chown=65534:65534 app.py /app/app.py

# コンテナの設定
ENV FLASK_APP=app
EXPOSE 9100
CMD ["flask", "run", "--host", "0.0.0.0", "--port", "9100"]


49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

## イメージのビルド

~~~
$ ls
Dockerfile README.md app.py
$ docker build -t ex1:1.0 .
~~~

## イメージの実行


~~~
docker run --name ex1 --publish 9100:9100 --detach ex1:1.0
~~~

## アクセス

~~~
curl http://localhost:9100/ping;echo
~~~

## コンテナへ入る

~~~
docker exec -it ex1 bash
~~~

## イメージをレジストリへ登録

~~~
export CR_PAT=YOUR_TOKEN
export USERNAME=YOUR USERID
echo $CR_PAT | docker login ghcr.io -u $USERNAME --password-stdin
docker tag ex1:1.0 ghcr.io/takara9/ex1:1.0
docker push ghcr.io/takara9/ex1:1.0
~~~

## クリーンナップ

~~~
docker stop ex1
docker rm ex1
docker rmi ghcr.io/takara9/ex1:1.0
docker rmi ex1:1.0
~~~


7 changes: 7 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from flask import Flask

app = Flask(__name__)

@app.route("/ping")
def hello_world():
return "<p>pong</p>"

0 comments on commit ff1f2b5

Please sign in to comment.