Changes
6 changed files (+43/-225)
-
-
@@ -33,10 +33,6 @@"exts": ["tf"], "command": "tofu fmt -" }, { "exts": ["go"], "command": "gofmt" }, { "exts": ["nix"], "command": "nixfmt --strict --width={{line_width}} --indent={{indent_width}}"
-
-
-
@@ -28,8 +28,6 @@system: let pkgs = nixpkgs.legacyPackages.${system}; deploy-docs = pkgs.callPackage ./tools/deploy-docs { }; in rec { packages = {
-
@@ -50,10 +48,6 @@# https://hackage.haskell.org/package/nixfmt nixfmt-rfc-style # Go Programming language # https://go.dev/ go # Tool for building, changing, and versioning infrastructure # https://opentofu.org/ opentofu
-
@@ -103,16 +97,42 @@type = "app"; program = pkgs.lib.getExe ( pkgs.writeShellApplication { name = "deploy-docs-wrapped"; name = "deploy-docs"; text = '' ${pkgs.lib.getExe deploy-docs} -dir ${packages.docs} -tf-dir docs CF_DIST_ID=$(tofu -chdir=docs output -json | jq -r ".cloudfront_distribution_id.value") S3_BUCKET_NAME=$(tofu -chdir=docs output -json | jq -r ".s3_bucket_name.value") rclone sync \ ${packages.docs} \ ":s3:$S3_BUCKET_NAME" \ --s3-provider=AWS \ --s3-env-auth \ --s3-region="$AWS_DEFAULT_REGION" \ --checksum aws cloudfront create-invalidation \ --distribution-id "$CF_DIST_ID" --paths '/*' ''; runtimeInputs = with pkgs; [ pkgs.makeWrapper packages.docs deploy-docs # Tool for building, changing, and versioning infrastructure # https://opentofu.org/ opentofu # Unified tool to manage your AWS services # https://aws.amazon.com/cli/ awscli2 # Lightweight and flexible command-line JSON processor # https://jqlang.github.io/jq/ jq # Command line program to sync files and directories to and from major cloud storage # https://rclone.org/ rclone ]; } );
-
@@ -120,30 +140,19 @@}; devShell = pkgs.mkShell { packages = with pkgs; [ # Code formatting platform written in Rust # https://dprint.dev/ dprint # Official formatter for Nix code # https://hackage.haskell.org/package/nixfmt nixfmt-rfc-style # Copyright and license linter based on SPDX # https://github.com/fsfe/reuse-tool reuse # Go Programming language # https://go.dev/ go # Official language server for the Go language # https://github.com/golang/tools/tree/master/gopls gopls ] ++ deploy-docs.buildInputs; packages = with pkgs; [ # Code formatting platform written in Rust # https://dprint.dev/ dprint # Official formatter for Nix code # https://hackage.haskell.org/package/nixfmt nixfmt-rfc-style # Copyright and license linter based on SPDX # https://github.com/fsfe/reuse-tool reuse ]; }; } );
-
-
tools/deploy-docs/default.nix (deleted)
-
@@ -1,49 +0,0 @@# SPDX-License-Identifier: AGPL-3.0-only # Copyright 2025 Shota FUJI # # This program is free software: you can redistribute it and/or modify it under the terms # of the GNU Affero General Public License as published by the Free Software Foundation, # either version 3 of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, but WITHOUT ANY # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A # PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License along # with this program. If not, see <http://www.gnu.org/licenses/>. { buildGoModule, lib, awscli2, opentofu, }: buildGoModule { name = "deploy-docs"; src = lib.sourceFilesBySuffices ./. [ ".go" ".mod" ]; buildInputs = [ # Unified tool to manage your AWS services # https://aws.amazon.com/cli/ awscli2 # Tool for building, changing, and versioning infrastructure # https://opentofu.org/ opentofu ]; vendorHash = null; ldflags = [ "-X main.awsCliBin=${awscli2}/bin/aws" "-X pocka.jp/yamori/deploydocs/tofu.tofuBin=${opentofu}/bin/tofu" ]; meta = { mainProgram = "deploydocs"; }; }
-
-
tools/deploy-docs/go.mod (deleted)
-
@@ -1,6 +0,0 @@// SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: AGPL-3.0-only module pocka.jp/yamori/deploydocs go 1.24.1
-
-
tools/deploy-docs/main.go (deleted)
-
@@ -1,65 +0,0 @@// tools/deploy-docs/cmd.go -- ドキュメントサイトのデプロイCLI // // SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: AGPL-3.0-only package main import ( "flag" "fmt" "log" "os" "os/exec" "pocka.jp/yamori/deploydocs/tofu" ) var awsCliBin = "aws" func main() { tfDir := flag.String("tf-dir", "", "Tofu を実行したディレクトリ") dir := flag.String("dir", "", "デプロイするディレクトリ") flag.Parse() if dir == nil || *dir == "" { log.Fatal("dir は必須です") } if tfDir == nil || *tfDir == "" { log.Fatal("tf-dir は必須です") } output, err := tofu.NewOutput(*tfDir) if err != nil { log.Fatal(err) } s3Sync := exec.Command( awsCliBin, "s3", "sync", "--delete", *dir, fmt.Sprintf("s3://%s", output.S3BucketName), ) s3Sync.Stdin = os.Stdin s3Sync.Stdout = os.Stdout s3Sync.Stderr = os.Stderr if err := s3Sync.Run(); err != nil { log.Fatal(err) } cfInvalidation := exec.Command( awsCliBin, "cloudfront", "create-invalidation", "--distribution-id", output.CloudfrontDistributionID, "--paths", "/*", ) cfInvalidation.Stdin = os.Stdin cfInvalidation.Stdout = os.Stdout cfInvalidation.Stderr = os.Stderr if err := cfInvalidation.Run(); err != nil { log.Fatal(err) } }
-
-
tools/deploy-docs/tofu/tofu.go (deleted)
-
@@ -1,67 +0,0 @@// SPDX-FileCopyrightText: 2025 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: AGPL-3.0-only package tofu import ( "encoding/json" "fmt" "log" "os/exec" ) var tofuBin = "tofu" type stringOutput struct { Value string } type rawOutput struct { CloudfrontDistributionID stringOutput `json:"cloudfront_distribution_id"` S3BucketName stringOutput `json:"s3_bucket_name"` } type Output struct { CloudfrontDistributionID string S3BucketName string } func NewOutput(tfDir string) (*Output, error) { cmd := exec.Command(tofuBin, fmt.Sprintf("-chdir=%s", tfDir), "output", "-json") stdout, err := cmd.StdoutPipe() if err != nil { return nil, err } if err := cmd.Start(); err != nil { return nil, err } var raw rawOutput if err := json.NewDecoder(stdout).Decode(&raw); err != nil { return nil, fmt.Errorf("Tofu の出力を読み込めませんでした: %s", err) } if err := cmd.Wait(); err != nil { return nil, err } output := Output{ CloudfrontDistributionID: raw.CloudfrontDistributionID.Value, S3BucketName: raw.S3BucketName.Value, } if output.CloudfrontDistributionID == "" { return nil, fmt.Errorf("cloudfront_distribution_id が取得できませんでした") } if output.S3BucketName == "" { return nil, fmt.Errorf("s3_bucket_name が取得できませんでした") } log.Printf("cloudfront_distribution_id: %s\n", output.CloudfrontDistributionID) log.Printf("s3_bucket_name: %s\n", output.S3BucketName) return &output, nil }
-