diff --git a/.github/workflows/container-creator.yml b/.github/workflows/container-creator.yml new file mode 100644 index 0000000..31360bf --- /dev/null +++ b/.github/workflows/container-creator.yml @@ -0,0 +1,50 @@ +name: Build and Push Image (Docker Buildx; GitHub Actions) + +on: + push: + tags: + - 'v*' + +env: + DOCKER_REGISTRY_NAME: ghcr.io + DOCKER_IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker hub + uses: docker/login-action@v1 + with: + registry: ${{ env.DOCKER_REGISTRY_NAME }} + username: ${{ github.repository_owner }} + password: ${{ github.token }} # github.token + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: ${{ env.DOCKER_REGISTRY_NAME }}/${{ env.DOCKER_IMAGE_NAME }} + + - name: Build & Push + uses: docker/build-push-action@v2 + env: + DOCKER_BUILDKIT: 1 + with: + context: . + push: true + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: ${{ env.DOCKER_REGISTRY_NAME }}/${{ env.DOCKER_IMAGE_NAME }}:latest + build-args: BUILDKIT_INLINE_CACHE=1 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1c28580 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +FROM golang:latest + +WORKDIR /app + +# 前提インストール +RUN dpkg --add-architecture armhf +RUN apt update && apt upgrade -y +RUN apt install pkg-config +RUN apt-get install -y gcc-arm-linux-gnueabihf libusb-1.0-0-dev libusb-1.0-0-dev:armhf + +ENV GOOS linux +ENV GOARCH arm +ENV GOARM 7 +ENV CGO_ENABLED 1 +ENV CC arm-linux-gnueabihf-gcc + +COPY go.mod go.sum ./ +RUN go mod download +RUN go mod tidy + +# ソースコードのコピー +COPY . . + +# ビルド +RUN go build -o /main ./cmd + +RUN ls -l /app + +CMD [ "/main" ] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..6d4f285 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,8 @@ +services: + playlist: + build: . + volumes: + - .:/app + devices: + - "/dev/bus/usb:/dev/bus/usb" + - "/dev/gpiomem:/dev/gpiomem" \ No newline at end of file