-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ff1f2b5
Showing
6 changed files
with
226 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
~~~ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>" |