Skip to content

Commit

Permalink
Merge pull request #238 from databacker/go
Browse files Browse the repository at this point in the history
switch to go binary
  • Loading branch information
deitch authored Nov 7, 2023
2 parents e3f3bf6 + 7e1bc53 commit dd5fcda
Show file tree
Hide file tree
Showing 71 changed files with 6,204 additions and 1,462 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ jobs:
steps:
- name: checkout
uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '1.19'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
- name: Build
run: go build -o dist/mysql-backup -v .
- name: vet
run: make vet
- name: Test
run: make test
- name: Integration Test
run: make integration_test
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
Expand Down
20 changes: 16 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,24 @@ jobs:
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push
id: docker_build
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
${{env.IMAGE_NAME}}
# generate Docker tags based on the following events/attributes
# for any semver, including rc and alpha, etc. take the tag as is
# for ones that are exactly X.Y.Z, also tag it as latest
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}.{{patch}},value=latest
- name: Build and push semver tag
id: docker_build_push_semver
uses: docker/build-push-action@v2
with:
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{env.IMAGE_NAME}}:${{ github.ref_name }}
${{env.IMAGE_NAME}}:latest
${{ steps.meta.outputs.tags }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
tmp/
30 changes: 14 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
# mysql backup image
FROM alpine:3.17
LABEL org.opencontainers.image.authors="https://github.com/deitch"
FROM golang:1.19.6-alpine3.17 as build

COPY . /src/mysql-backup
WORKDIR /src/mysql-backup

# install the necessary client
# the mysql-client must be 10.3.15 or later
RUN apk add --update 'mariadb-client>10.3.15' mariadb-connector-c bash python3 py3-pip samba-client shadow openssl coreutils && \
rm -rf /var/cache/apk/* && \
touch /etc/samba/smb.conf && \
pip3 install awscli
RUN mkdir /out && go build -o /out/mysql-backup .

# we would do from scratch, but we need basic utilities in order to support pre/post scripts
FROM alpine:3.17
LABEL org.opencontainers.image.authors="https://github.com/databacker"

# set us up to run as non-root user
RUN groupadd -g 1005 appuser && \
useradd -r -u 1005 -g appuser appuser
# add home directory for user so IRSA AWS auth works
RUN mkdir -p /home/appuser && chmod 0755 /home/appuser && chown appuser /home/appuser
# ensure smb stuff works correctly
RUN mkdir -p /var/cache/samba && chmod 0755 /var/cache/samba && chown appuser /var/cache/samba && chown appuser /var/lib/samba/private
RUN apk add bash
RUN addgroup -g 1005 appuser && \
adduser -u 1005 -G appuser -D appuser
USER appuser

# install the entrypoint
COPY functions.sh /
COPY --from=build /out/mysql-backup /mysql-backup

COPY entrypoint /entrypoint

# start
Expand Down
30 changes: 10 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ push: build
docker tag $(BUILDIMAGE) $(TARGET)
docker push $(TARGET)

test_dump:
cd test && DEBUG=$(DEBUG) ./test_dump.sh
integration_test:
go test -v ./test --tags=integration

test_cron:
cd test && ./test_cron.sh
integration_test_debug:
dlv --wd=./test test ./test --build-flags="-tags=integration"

test_source_target:
cd test && ./test_source_target.sh
vet:
go vet --tags=integration ./...

test_restore:
cd test && ./test_restore.sh
test: unit_test integration_test

test: test_dump test_restore test_cron test_source_target
unit_test:
go test -v ./...

.PHONY: clean-test-stop clean-test-remove clean-test
clean-test-stop:
Expand All @@ -39,15 +39,5 @@ clean-test-remove:
$(eval IDS:=$(shell docker ps -a --filter label=mysqltest -q))
@if [ -n "$(IDS)" ]; then docker rm $(IDS); fi
@echo
@echo Remove Volumes
$(eval IDS:=$(shell docker volume ls --filter label=mysqltest -q))
@if [ -n "$(IDS)" ]; then docker volume rm $(IDS); fi
@echo

clean-test-network:
@echo Remove Networks
$(eval IDS:=$(shell docker network ls --filter label=mysqltest -q))
@if [ -n "$(IDS)" ]; then docker network rm $(IDS); fi
@echo

clean-test: clean-test-stop clean-test-remove clean-test-network
clean-test: clean-test-stop clean-test-remove
381 changes: 381 additions & 0 deletions README-bash.md

Large diffs are not rendered by default.

Loading

0 comments on commit dd5fcda

Please sign in to comment.