Build other docker images #504
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build other docker images | |
on: | |
repository_dispatch: | |
types: | |
- build_other_docker_images | |
schedule: | |
# Times are in UTC, this job is run daily @ 9HRS = 4AM EST | |
- cron: '0 9 * * *' | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{secrets.LP_DOCKER_USERNAME}} | |
password: ${{secrets.LP_DOCKER_TOKEN}} | |
- name: set up qemu | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
id: buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: get versions | |
run: | | |
set -x | |
## obico-server | |
_app=obico-server | |
echo "_repo=${{secrets.LP_DOCKER_USERNAME}}/${_app}" >> $GITHUB_ENV | |
set +e | |
_local=$( cat "script/${_app}.sha" ) | |
set -e | |
_remote=$( git ls-remote "https://github.com/TheSpaghettiDetective/${_app}.git" HEAD | cut -f1 ) | |
if [ "${_local}" = "${_remote}" ]; then | |
echo "_build=false" >> $GITHUB_ENV | |
else | |
echo "${_remote}" > "script/${_app}.sha" | |
git config --local user.email "[email protected]" | |
git config --local user.name "Ali Mustakim" | |
git add . | |
git commit -a -m "github actions update" | |
git push | |
echo "_build=true" >> $GITHUB_ENV | |
fi | |
- name: checkout ${{env._repo}} | |
if: env._build == 'true' | |
uses: actions/checkout@v4 | |
with: | |
repository: TheSpaghettiDetective/obico-server | |
- name: build and push ${{env._repo}} | |
id: docker | |
if: env._build == 'true' | |
uses: docker/build-push-action@v5 | |
with: | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
context: backend | |
platforms: linux/amd64 | |
push: true | |
tags: ${{env._repo}}:latest | |
- name: tweet on success | |
if: steps.docker.outcome == 'success' | |
env: | |
LP_T_CONSUMER_KEY: ${{ secrets.LP_T_CONSUMER_KEY }} | |
LP_T_CONSUMER_SECRET: ${{ secrets.LP_T_CONSUMER_SECRET }} | |
LP_T_OAUTH_SECRET: ${{ secrets.LP_T_OAUTH_SECRET }} | |
LP_T_OAUTH_TOKEN: ${{ secrets.LP_T_OAUTH_TOKEN }} | |
run: | | |
# Code bits from - https://github.com/moebiuscurve/tweetExperiments/tree/master/curlTweets | |
repo_name=$( echo "$GITHUB_REPOSITORY" | awk -F / '{ print $2 }' ) | |
message="${repo_name} built and pushed to Docker Hub" | |
message_string=$( echo -n "${message}" | sed -e s'/ /%2520/g' ) | |
message_curl=$( echo -n "${message}" | sed -e s'/ /+/g' ) | |
timestamp=$( date +%s ) | |
nonce=$( date +%s%T | openssl base64 | sed -e s'/[+=/]//g' ) | |
api_version="1.1" | |
signature_base_string="POST&https%3A%2F%2Fapi.twitter.com%2F${api_version}%2Fstatuses%2Fupdate.json&oauth_consumer_key%3D${LP_T_CONSUMER_KEY}%26oauth_nonce%3D${nonce}%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D${timestamp}%26oauth_token%3D${LP_T_OAUTH_TOKEN}%26oauth_version%3D1.0%26status%3D${message_string}" | |
signature_key="${LP_T_CONSUMER_SECRET}&${LP_T_OAUTH_SECRET}" | |
oauth_signature=$( echo -n "${signature_base_string}" | openssl dgst -sha1 -hmac "${signature_key}" -binary | openssl base64 | sed -e s'/+/%2B/g' -e s'/\//%2F/g' -e s'/=/%3D/g' ) | |
header="Authorization: OAuth oauth_consumer_key=\"${LP_T_CONSUMER_KEY}\", oauth_nonce=\"${nonce}\", oauth_signature=\"${oauth_signature}\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"${timestamp}\", oauth_token=\"${LP_T_OAUTH_TOKEN}\", oauth_version=\"1.0\"" | |
result=$( curl -s -X POST "https://api.twitter.com/${api_version}/statuses/update.json" --data "status=${message_curl}" --header "Content-Type: application/x-www-form-urlencoded" --header "${header}" ) |