-
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.
Merge pull request #201 from ueckoken/write-dockerfile
state-managerのDockerfileを書いてActionsでghcrにプッシュするようにした
- Loading branch information
Showing
7 changed files
with
104 additions
and
11 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,61 @@ | ||
name: build and publish image | ||
|
||
on: | ||
push: | ||
branches: | ||
- "main" | ||
- "deployment" | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Extract branch name | ||
shell: bash | ||
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT | ||
id: extract_branch | ||
|
||
- name: Generate tag | ||
id: generate_tag | ||
shell: bash | ||
run: echo "tag=$(echo ${{ github.sha }} | cut -c1-7)-$(date +%s)" >> $GITHUB_OUTPUT | ||
|
||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Bake images | ||
uses: docker/bake-action@v4 | ||
env: | ||
TAG: ${{ steps.generate_tag.outputs.tag }} | ||
with: | ||
files: ./docker-bake.hcl | ||
push: ${{ github.event_name == 'push' && startsWith( steps.extract_branch.outputs.branch , 'deployment' ) }} | ||
set: | | ||
*.cache-from=type=local,src=/tmp/.buildx-cache | ||
*.cache-to=type=local,mode=min,dest=/tmp/.buildx-cache-new | ||
provenance: false | ||
|
||
# https://github.com/docker/build-push-action/issues/252#issuecomment-744400434 | ||
- name: Move Cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache | ||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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,29 @@ | ||
group "default" { | ||
targets = [ | ||
"state-manager" | ||
] | ||
} | ||
|
||
variable "PREFIX" { | ||
default = "plarail2023" | ||
} | ||
|
||
variable "TAG" { | ||
default = "latest" | ||
} | ||
|
||
function "GET_TAG" { | ||
params = [image] | ||
result = "ghcr.io/ueckoken/${PREFIX}-${image}:${TAG}" | ||
} | ||
|
||
target "state-manager" { | ||
dockerfile = "docker/backend/state-manager/Dockerfile" | ||
tags = [ | ||
GET_TAG("state-manager") | ||
] | ||
platforms = [ | ||
"linux/amd64", | ||
"linux/arm64" | ||
] | ||
} |
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,14 @@ | ||
FROM --platform=$BUILDPLATFORM golang:1.21-bookworm AS builder | ||
WORKDIR /state-manager | ||
ARG TARGETOS | ||
ARG TARGETARCH | ||
ENV GOOS=${TARGETOS} | ||
ENV GOARCH=${TARGETARCH} | ||
COPY go.mod go.sum ./ | ||
RUN go mod download | ||
COPY . ./ | ||
RUN go build -o state-manager backend/state-manager/cmd/main.go | ||
|
||
FROM --platform=$TARGETPLATFORM gcr.io/distroless/base-debian12:nonroot AS runner | ||
COPY --from=builder /state-manager/state-manager /state-manager | ||
ENTRYPOINT ["/state-manager"] |