Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 65 additions & 65 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,83 +3,83 @@ version: 2
jobs:
build:
docker:
- image: circleci/golang:1.10.3
- image: circleci/golang:1.10.3
working_directory: /go/src/github.com/joshdk/docker-retag
steps:
- checkout
- run:
name: Describe commit
command: git describe --tags
- run:
name: Run tests
command: |
gofmt -l -s -w .
go vet -all -shadow=true .
go test -race -v ./...
- run:
name: Build binary
command: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_linux_amd64 .
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_darwin_amd64 .
- run:
name: Install UPX
working_directory: /tmp
command: |
wget https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
tar --strip=1 -xf upx-3.94-amd64_linux.tar.xz
sudo install upx /usr/bin
- run:
name: Compress binary
command: upx --best --ultra-brute artifacts/docker-retag*
- run:
name: Copy binary
command: cp artifacts/docker-retag_linux_amd64 artifacts/docker-retag
- run:
name: Checksum binary
working_directory: artifacts
command: sha256sum --binary --tag docker-retag* | tee checksums.txt
- store_artifacts:
path: artifacts
destination: /artifacts
- persist_to_workspace:
root: .
paths:
- artifacts
- checkout
- run:
name: Describe commit
command: git describe --tags
- run:
name: Run tests
command: |
gofmt -l -s -w .
go vet -all -shadow=true .
go test -race -v ./...
- run:
name: Build binary
command: |
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_linux_amd64 .
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_darwin_amd64 .
- run:
name: Install UPX
working_directory: /tmp
command: |
wget https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
tar --strip=1 -xf upx-3.94-amd64_linux.tar.xz
sudo install upx /usr/bin
- run:
name: Compress binary
command: upx --best --ultra-brute artifacts/docker-retag*
- run:
name: Copy binary
command: cp artifacts/docker-retag_linux_amd64 artifacts/docker-retag
- run:
name: Checksum binary
working_directory: artifacts
command: sha256sum --binary --tag docker-retag* | tee checksums.txt
- store_artifacts:
path: artifacts
destination: /artifacts
- persist_to_workspace:
root: .
paths:
- artifacts

release:
docker:
- image: cibuilds/github:0.12.0
- image: cibuilds/github:0.12.0
working_directory: /go/src/github.com/joshdk/docker-retag
steps:
- attach_workspace:
at: .
- run:
name: Upload artifacts
command: ghr -u joshdk -r docker-retag -replace ${CIRCLE_TAG} artifacts
- attach_workspace:
at: .
- run:
name: Upload artifacts
command: ghr -u joshdk -r docker-retag -replace ${CIRCLE_TAG} artifacts

workflows:
version: 2
build:
jobs:
- build
- build

release:
jobs:
- build:
filters:
branches:
ignore: /.*/
tags:
only: /.*/
- release:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /.*/
- build:
filters:
branches:
ignore: /.*/
tags:
only: /.*/
- release:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /.*/
92 changes: 92 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Build and Release

on:
push:
branches: [master]
pull_request:
branches: [master]
release:
types: [created]
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "stable"

- name: Describe commit
run: git describe --tags || echo "No tags found"

- name: Run gofmt
run: gofmt -l -s -w .

- name: Run go vet
run: go vet ./...

- name: Run tests
run: go test -race -v ./...

- name: Build Linux binary
run: |
mkdir -p artifacts
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_linux_amd64 .

- name: Build Darwin binary
run: |
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -a \
-ldflags="-s -w" \
-o artifacts/docker-retag_darwin_amd64 .

- name: Install UPX
run: |
sudo apt-get update
sudo apt-get install -y xz-utils wget
wget https://github.com/upx/upx/releases/download/v3.94/upx-3.94-amd64_linux.tar.xz
tar --strip=1 -xf upx-3.94-amd64_linux.tar.xz
sudo install upx /usr/bin

- name: Compress binaries
run: upx --best --ultra-brute artifacts/docker-retag*

- name: Copy Linux binary
run: cp artifacts/docker-retag_linux_amd64 artifacts/docker-retag

- name: Checksum binaries
run: sha256sum --binary --tag artifacts/docker-retag* | tee artifacts/checksums.txt

- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: docker-retag-artifacts
path: artifacts/

release:
needs: build
if: github.event_name == 'release'
runs-on: ubuntu-latest
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: docker-retag-artifacts
path: artifacts

- name: Upload Release Assets
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/docker-retag_linux_amd64
artifacts/docker-retag_darwin_amd64
artifacts/docker-retag
artifacts/checksums.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18 changes: 15 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,27 @@ func mainCmd(args []string) error {
func login(repo string, username string, password string) (string, error) {
var (
client = http.DefaultClient
url = "https://auth.docker.io/token?service=registry.docker.io&scope=repository:" + repo + ":pull,push"
url = "https://hub.docker.com/v2/users/login"
)

req, err := http.NewRequest("GET", url, nil)
req, err := http.NewRequest("POST", url, nil)
if err != nil {
return "", err
}

// Authenticate using JSON payload
payload := map[string]string{
"username": username,
"password": password,
}

payloadBytes, err := json.Marshal(payload)
if err != nil {
return "", err
}

req.SetBasicAuth(username, password)
req.Body = ioutil.NopCloser(bytes.NewReader(payloadBytes))
req.Header.Set("Content-Type", "application/json")

resp, err := client.Do(req)
if err != nil {
Expand Down
Loading