Skip to content

Commit

Permalink
chore: added docker for actions
Browse files Browse the repository at this point in the history
  • Loading branch information
giautm committed Dec 11, 2024
1 parent 6bb7a04 commit 7f9ab3b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
84 changes: 84 additions & 0 deletions .github/workflows/cd-docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Build Docker Image
on:
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Install Atlas
uses: ariga/setup-atlas@v0
- name: Checkout code
uses: actions/[email protected]
with:
ref: ${{ github.event.inputs.commit || 'master' }}
- name: Setup Go Environment
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Compile Go Binary
run: |
COMMIT=$(git rev-parse --short HEAD)
go build -o atlas-action -ldflags "-s -w -X main.version=$VERSION -X main.commit=$COMMIT" ./cmd/atlas-action
OUTPUT=$(./atlas-action --version)
if [[ $(echo $OUTPUT | grep -i "^atlas-action version $VERSION-$COMMIT") ]]; then
echo "Version=$OUTPUT"
else
echo "unexpected output: $OUTPUT, expected: atlas-action version $VERSION-$COMMIT"
exit 1
fi
env:
CGO_ENABLED: 0
VERSION: ${{ github.event.inputs.version || github.ref_name }}
- uses: actions/upload-artifact@v4
with:
name: atlas-action
path: ./atlas-action
docker:
needs: build
name: Docker (atlas-action)
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
env:
REGISTRY: "ghcr.io"
IMAGE_NAME: ${{ github.repository }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download the binary
uses: actions/download-artifact@v4
with:
name: atlas-action
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=sha
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
labels: ${{ steps.meta.outputs.labels }}
tags: ${{ steps.meta.outputs.tags }}
push: true
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2021-present The Atlas Authors. All rights reserved.
# This source code is licensed under the Apache 2.0 license found
# in the LICENSE file in the root directory of this source tree.
# syntax=docker/dockerfile:1

ARG ALPINE_VERSION="3.21"

FROM alpine:${ALPINE_VERSION}
COPY LICENSE README.md /
COPY --chmod=001 ./scripts/setup-atlas.sh /usr/local/bin/setup-atlas
COPY --chmod=001 ./atlas-action /usr/local/bin/
RUN apk add --update --no-cache curl
RUN setup-atlas && rm -rf /root/.atlas /tmp/*
WORKDIR /root
VOLUME /root/.atlas
ENTRYPOINT ["/usr/local/bin/atlas-action"]
2 changes: 1 addition & 1 deletion cmd/atlas-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (v VersionFlag) BeforeReset(app *kong.Kong) error {

// RunActionCmd is a command to run one of the Atlas GitHub Actions.
type RunActionCmd struct {
Action string `help:"Command to run" required:""`
Action string `help:"Command to run" required:"" env:"ATLAS_ACTION"`
Version VersionFlag `help:"Prints the version and exits"`
}

Expand Down
10 changes: 10 additions & 0 deletions scripts/setup-atlas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env sh
# Copyright 2021-present The Atlas Authors. All rights reserved.
# This source code is licensed under the Apache 2.0 license found
# in the LICENSE file in the root directory of this source tree.

set -e
curl -sSf https://atlasgo.sh | sh
if [ -n "$ATLAS_TOKEN" ]; then
atlas login --token $ATLAS_TOKEN
fi

0 comments on commit 7f9ab3b

Please sign in to comment.