-
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
Showing
4 changed files
with
155 additions
and
1 deletion.
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,121 @@ | ||
name: FileTree-API Docker Build and Push | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'go-filetree-api-*' | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
include: | ||
- os: ubuntu-latest | ||
platform: linux/amd64 | ||
- os: buildjet-2vcpu-ubuntu-2204-arm | ||
platform: linux/arm64 | ||
outputs: | ||
version: ${{ env.version }} | ||
latest: ${{ env.IS_LATEST }} | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Check out Sharp-API repo | ||
uses: actions/checkout@v4 | ||
with: | ||
repository: 'carry0987/FileTree-API' | ||
token: ${{ secrets.GH_CLONE_TOKEN }} | ||
path: 'Go/FileTree-API/source' | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Prepare the Docker tags list | ||
id: prep | ||
run: | | ||
FULL_VERSION=$(echo ${{ github.ref }} | sed -e 's,.*/go-filetree-api-,,') | ||
VERSION=${FULL_VERSION%-latest} | ||
TAGS="${{ secrets.DOCKER_USERNAME }}/filetree-api:${VERSION}" | ||
IS_LATEST=false | ||
if [[ ${{ matrix.platform }} == "linux/amd64" ]]; then | ||
SUFFIX="-amd64" | ||
elif [[ ${{ matrix.platform }} == "linux/arm64" ]]; then | ||
SUFFIX="-arm64" | ||
fi | ||
TAGS="${{ secrets.DOCKER_USERNAME }}/filetree-api:${VERSION}${SUFFIX}" | ||
if [[ "$FULL_VERSION" == *"-latest" ]]; then | ||
TAGS="$TAGS,${{ secrets.DOCKER_USERNAME }}/filetree-api:latest${SUFFIX}" | ||
IS_LATEST=true | ||
fi | ||
echo "TAGS=$TAGS" >> $GITHUB_ENV | ||
echo "PROGRAM_VERSION=${VERSION%}" >> $GITHUB_ENV | ||
echo "version=${VERSION%}" >> $GITHUB_ENV | ||
echo "IS_LATEST=$IS_LATEST" >> $GITHUB_ENV | ||
echo "PROGRAM_VERSION=${VERSION%}" | ||
echo "Building with tags: $TAGS" | ||
- name: Start multi-arch build and push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: Go/FileTree-API | ||
file: Go/FileTree-API/Dockerfile | ||
build-args: PROGRAM_VERSION=${{ env.PROGRAM_VERSION }} | ||
push: true | ||
tags: ${{ env.TAGS }} | ||
platforms: ${{ matrix.platform }} | ||
provenance: false | ||
|
||
- name: Logout from DockerHub | ||
run: docker logout | ||
|
||
manifest: | ||
needs: build-and-push | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out the repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Login to DockerHub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_TOKEN }} | ||
|
||
- name: Set image prefix | ||
run: echo "IMAGE_PREFIX=${{ secrets.DOCKER_USERNAME }}/filetree-api:${{ needs.build-and-push.outputs.version }}" >> $GITHUB_ENV | ||
|
||
- name: Create and push manifest images | ||
uses: Noelware/docker-manifest-action@master | ||
with: | ||
inputs: ${{ secrets.DOCKER_USERNAME }}/filetree-api:${{ needs.build-and-push.outputs.version }} | ||
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64 | ||
push: true | ||
amend: true | ||
|
||
- name: Check outputs for latest | ||
run: echo "Latest ${{ needs.build-and-push.outputs.latest }}" | ||
|
||
- name: Set image prefix for latest | ||
if: ${{ needs.build-and-push.outputs.latest == 'true' }} | ||
run: echo "IMAGE_PREFIX=${{ secrets.DOCKER_USERNAME }}/filetree-api:latest" >> $GITHUB_ENV | ||
|
||
- name: Create and push manifest images for latest | ||
if: ${{ needs.build-and-push.outputs.latest == 'true' }} | ||
uses: Noelware/docker-manifest-action@master | ||
with: | ||
inputs: ${{ env.IMAGE_PREFIX }} | ||
images: ${{ env.IMAGE_PREFIX }}-amd64,${{ env.IMAGE_PREFIX }}-arm64 | ||
push: true | ||
amend: true | ||
|
||
- name: Logout from DockerHub | ||
run: docker logout |
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,26 @@ | ||
# Build stage | ||
FROM golang:1.21 AS builder | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Copy the code from the GitHub Actions "Go/FileTree-API/source" directory | ||
COPY source ./ | ||
|
||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed | ||
RUN go mod download | ||
|
||
# Build the Go app | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o filetree cmd/server/main.go | ||
|
||
# Production stage | ||
FROM --platform=$TARGETPLATFORM alpine:latest | ||
|
||
# Set the working directory | ||
WORKDIR /root/ | ||
|
||
# Copy the Pre-built binary file from the previous stage | ||
COPY --from=builder /app/filetree . | ||
|
||
# Set the entry point | ||
CMD ["./filetree"] |
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,2 @@ | ||
# Docker-Go | ||
This is a Docker image list for Go, suitable for various Web application developments. |
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