Skip to content

Commit

Permalink
feat: release to docker hub when release
Browse files Browse the repository at this point in the history
  • Loading branch information
mmuller88 committed Jan 15, 2021
1 parent 61ad99d commit 1b92593
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 11 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/push-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ~~ Generated by projen. To modify, edit .projenrc.js and run "npx projen".
name: push-docker
on:
release:
types:
- published
workflow_dispatch: {}
jobs:
publish_docker_hub:
runs-on: ubuntu-latest
env:
CI: "true"
steps:
- name: Push to Docker Hub
uses: docker/build-push-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
repository: damadden88/influxdb-s3-backup
tag_with_ref: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ yarn-error.log*
!/.github/dependabot.yml
!/.github/pull_request_template.md
!/.github/workflows/build.yml
!/.github/workflows/push-docker.yml
!/.github/workflows/rebuild-bot.yml
!/.github/workflows/release.yml
!/.mergify.yml
Expand Down
51 changes: 45 additions & 6 deletions .projenrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,65 @@ const project = new NodeProject({
name: 'influxdb-s3-backup',
releaseBranches: 'main',
projectType: ProjectType.LIB,

});

const dockerPush = project.github.addWorkflow('push-docker');

dockerPush.addJobs({
publish_docker_hub: {
// 'name': 'Release to NPM',
// 'needs': this.releaseWorkflowJobId,
'runs-on': 'ubuntu-latest',
env: {
CI: "true",
},
'steps': [
{
name: 'Push to Docker Hub',
uses: 'docker/build-push-action@v1',
with: {
username: '${{ secrets.DOCKER_USERNAME }}',
password: '${{ secrets.DOCKER_PASSWORD }}',
repository: 'damadden88/influxdb-s3-backup',
tag_with_ref: true,
},
},
],
}
})

dockerPush.on({
release: {
types: ['published'],
},
workflow_dispatch: {},
})

new DockerCompose(project, {
version: '3.9',
version: '3.3',
services: {
influxdb:{
// container_na me: influxdb,
image: "influxdb:latest",
environment: {
INFLUXDB_DB: 'mydb',
INFLUXDB_BIND_ADDRESS: '0.0.0.0:8088',
},
},
influxdbs3backup: {
imageBuild: {
context: '.',
},
environment: {
DATABASE: 'mydatabase',
DATABASE_HOST: '1.2.3.4',
DATABASE: 'mydb',
DATABASE_HOST: 'influxdb',
S3_BUCKET: 'mybackupbucket',
AWS_ACCESS_KEY_ID: 'AKIAIOSFODNN7EXAMPLE',
AWS_SECRET_ACCESS_KEY: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY',
AWS_DEFAULT_REGION: 'us-west-2',
},
}
},
},
},
});

project.synth();
11 changes: 7 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@

version: '3.3'

services:
influxdb:
image: influxdb:latest
environment:
INFLUXDB_DB: mydb
INFLUXDB_BIND_ADDRESS: 0.0.0.0:8088
influxdbs3backup:
build:
context: .
environment:
DATABASE: mydatabase
DATABASE_HOST: localhost
DATABASE: mydb
DATABASE_HOST: influxdb
S3_BUCKET: mybackupbucket
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Expand Down
9 changes: 8 additions & 1 deletion influxdb-to-s3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export DATETIME=$(date "+%Y%m%d%H%M%S")
# Add this script to the crontab and start crond
startcron() {
echo "export S3_BUCKET=$S3_BUCKET" >> $HOME/.profile
echo "export S3_KEY_PREFIX=$S3_KEY_PREFIX" >> $HOME/.profile
echo "export DATABASE_HOST=$DATABASE_HOST" >> $HOME/.profile
echo "export DATABASE=$DATABASE" >> $HOME/.profile
echo "export DATABASE_PORT=$DATABASE_PORT" >> $HOME/.profile
echo "export BACKUP_PATH=$BACKUP_PATH" >> $HOME/.profile
echo "export BACKUP_ARCHIVE_PATH=$BACKUP_ARCHIVE_PATH" >> $HOME/.profile
echo "export DATETIME=$DATETIME" >> $HOME/.profile
echo "Starting backup cron job with frequency '$1'"

echo "$1 . $HOME/.profile; $0 backup >> /var/log/cron.log 2>&1" > /etc/cron.d/influxdbbackup
Expand All @@ -49,7 +56,7 @@ backup() {
rm -rf $BACKUP_PATH
fi
mkdir -p $BACKUP_PATH
influxd backup -database $DATABASE -host $DATABASE_HOST:$DATABASE_PORT $BACKUP_PATH
influxd backup -portable -database $DATABASE -host $DATABASE_HOST:$DATABASE_PORT $BACKUP_PATH
if [ $? -ne 0 ]; then
echo "Failed to backup $DATABASE to $BACKUP_PATH"
exit 1
Expand Down

0 comments on commit 1b92593

Please sign in to comment.