Skip to content

Commit

Permalink
Upload Docker images, fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Nov 16, 2020
1 parent 0993c04 commit 099fb61
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/home-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
outputs = { home-manager, lazyssh, ... }: {
homeManagerConfiguration = home-manager.lib.homeManagerConfiguration {
system = "x86_64-linux";
username = "runner";
username = "${USER}";
homeDirectory = "${HOME}";
configuration = {
imports = [ lazyssh.homeManagerModule ];
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ jobs:
release:
name: Release
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:

- name: Set up Go
Expand Down Expand Up @@ -37,3 +42,11 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./scripts/upload-release.sh "${GITHUB_REF#refs/tags/}"

- name: Upload Docker images
env:
SKOPEO_AUTH: ${{ secrets.SKOPEO_AUTH }}
run: |
mkdir -p "${HOME}/.config/containers"
echo "${SKOPEO_AUTH}" > "${HOME}/.config/containers/auth.json"
./scripts/upload-docker.sh "${GITHUB_REF#refs/tags/}"
12 changes: 7 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# This file doubles as .gitignore and .dockerignore

# Version control
.git
/.git

# Build products
lazyssh
/lazyssh

# Configuration
*.hcl
/*.hcl

# Release builds
lazyssh-*
/release

# Nix
result
/result
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ something to avoid conflict, create an issue for it.

- Multiple authorized keys.

- Homebrew package

- Persist state so any kind of interruption can recover management of an
instance. (We'd still interrupt all connections, but can hopefully prevent
accidental waste of resources this way.)
Expand All @@ -40,6 +42,8 @@ something to avoid conflict, create an issue for it.

- Google Cloud Compute

- Microsoft Azure VM

- DigitalOcean Droplets

- Hetzner Cloud
Expand Down
2 changes: 1 addition & 1 deletion doc/providers/forward.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Dummy forwarding target type

The `forward` target type does not actually create any resources, but simply
forwards to connection to a fixed address.
forwards the connection to a fixed address.

These are the available target options:

Expand Down
24 changes: 17 additions & 7 deletions scripts/build-release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env bash

# Creates release packages for all supported platforms.

set -euo pipefail

if [[ $# -ne 1 ]]; then
Expand All @@ -14,6 +17,11 @@ extras=(
"doc"
)

# TODO: Linux ARM builds. Need to build for variants.
# See: https://github.com/golang/go/wiki/GoArm
#
# TODO: Support darwin/arm64, but that currently means iOS.
# Need to wait for Go 1.16 in February.
build_targets=(
"GOOS=darwin GOARCH=amd64"
"GOOS=freebsd GOARCH=386 "
Expand All @@ -28,20 +36,22 @@ build_targets=(
)

set -x
export CGO_ENABLED=0

for build_target in "${build_targets[@]}"; do
eval export $build_target
go build .

pkgname="lazyssh-${version}-${GOOS}-${GOARCH}"
rm -fr "${pkgname}"
mkdir "${pkgname}"
cp -r "${extras[@]}" "./${pkgname}/"
rm -fr "./release/${pkgname}"
mkdir -p "./release/${pkgname}"
cp -r "${extras[@]}" "./release/${pkgname}/"

if [[ "${GOOS}" = "windows" ]]; then
mv lazyssh.exe "./${pkgname}/"
zip -r9 "${pkgname}.zip" "./${pkgname}"
mv lazyssh.exe "./release/${pkgname}/"
(cd ./release/ && zip -r9 "./${pkgname}.zip" "./${pkgname}")
else
mv lazyssh "./${pkgname}/"
tar -czf "${pkgname}.tar.gz" "./${pkgname}"
mv lazyssh "./release/${pkgname}/"
(cd ./release/ && tar -czf "${pkgname}.tar.gz" "./${pkgname}")
fi
done
59 changes: 59 additions & 0 deletions scripts/upload-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash

# Uploads binaries created by `build-release.sh` to Docker Hub.
#
# This script needs Docker running, and a Docker registry at
# `http://localhost:5000` to use as a scratch area. It also needs Skopeo
# installed to copy the final multi-arch image from the local registry to
# Docker Hub.

set -euo pipefail

if [[ $# -ne 1 ]]; then
echo >&2 "Usage: $0 VERSION"
exit 64
fi

version="$1"
major="$(echo "${version}" | cut -d . -f 1)"
scratch_repo="localhost:5000/lazyssh"
upload_repo="stephank/lazyssh"
manifest_list="${scratch_repo}:${version}"

# Must be a subset of the target architectures in `build-release.sh`.
build_archs=("386" "amd64")

manifests=()
for build_arch in "${build_archs[@]}"; do
manifest="${scratch_repo}:${build_arch}"
manifests+=("${manifest}")

echo "- Importing image ${manifest}"
tar -cC ./release/lazyssh-0.0-linux-${build_arch} lazyssh \
| docker import --change 'CMD ["/lazyssh"]' - "${manifest}"

echo "- Pushing image ${manifest}"
docker push "${manifest}"
done

echo "- Creating manifest list ${manifest_list}"
docker manifest create --insecure "${manifest_list}" "${manifests[@]}"

for build_arch in "${build_archs[@]}"; do
manifest="${scratch_repo}:${build_arch}"

echo "- Annotating ${manifest}"
docker manifest annotate \
--os linux --arch "${build_arch}" \
"${manifest_list}" "${manifest}"
done

echo "- Pushing manifest list ${manifest_list}"
docker manifest push --insecure --purge "${manifest_list}"

echo "- Copying to ${upload_repo}:${version}"
for tag in "${version}" "${major}" latest; do
skopeo --insecure-policy copy --all --src-tls-verify=false \
"docker://${manifest_list}" \
"docker://${upload_repo}:${tag}"
done
6 changes: 5 additions & 1 deletion scripts/upload-release.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/usr/bin/env bash

# Uploads release packages created by `build-release.sh` to the matching
# release on GitHub.

set -euo pipefail

if [[ $# -ne 1 ]]; then
Expand All @@ -9,7 +13,7 @@ fi
version="$1"

flags=("-m" "")
for pkg in ./lazyssh-${version}-*.{tar.gz,zip}; do
for pkg in ./release/lazyssh-${version}-*.{tar.gz,zip}; do
flags+=("-a" "${pkg}")
done

Expand Down

0 comments on commit 099fb61

Please sign in to comment.