Skip to content

Instantly share code, notes, and snippets.

@niwinz
Created July 29, 2021 07:55
Show Gist options
  • Save niwinz/64f67b4b700dbd75a714c212995827f0 to your computer and use it in GitHub Desktop.
Save niwinz/64f67b4b700dbd75a714c212995827f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -x
DOCKER_CLI_EXPERIMENTAL=enabled
ORG=${PENPOT_DOCKER_NAMESPACE:-penpotapp};
PLATFORM=${PENPOT_BUILD_PLATFORM:-linux/amd64};
IMAGE=${1:-backend};
DOCKER_IMAGE="$ORG/$IMAGE";
OPTIONS="--platform $PLATFORM -t $DOCKER_IMAGE:$PENPOT_BUILD_BRANCH";
IFS=", "
read -a TAGS <<< $PENPOT_BUILD_TAGS;
for element in "${TAGS[@]}"; do
OPTIONS="$OPTIONS -t $DOCKER_IMAGE:$element";
done
if [ "$PENPOT_BUILD_PUSH" = "true" ]; then
OPTIONS="--push $OPTIONS"
else
OPTIONS="--load $OPTIONS"
fi
docker buildx inspect penpot > /dev/null 2>&1;
if [ $? -eq 1 ]; then
docker buildx create --name=penpot --use
docker buildx inspect --bootstrap > /dev/null 2>&1;
else
docker buildx use penpot;
docker buildx inspect --bootstrap > /dev/null 2>&1;
fi
docker buildx build $OPTIONS -f Dockerfile.$IMAGE .;
---
# https://github.com/tonistiigi/binfmt#installing-emulators
- name: build & publish docker images
hosts: "localhost"
gather_facts: no
vars:
repo_dir: "{{inventory_dir}}/../repositories/penpot-images"
build_branch: "main"
# platform: "linux/amd64,linux/arm64,linux/arm/v7"
platform: "linux/amd64"
push: true
tasks:
- debug: "var=build_branch"
- name: pull image
community.general.docker_image:
name: penpotapp/devenv:latest
source: pull
state: present
# force_source: yes
- name: clone repo
git:
repo: https://github.com/penpot/penpot.git
dest: "{{repo_dir}}"
version: "{{build_branch}}"
update: true
force: true
- name: build bundle
shell:
chdir: "{{repo_dir}}"
cmd: "./manage.sh build-{{item}}-bundle"
loop:
- frontend
- backend
- exporter
- name: copy bundle
shell:
chdir: "{{repo_dir}}/bundle-{{item}}"
cmd: "rsync -avr --delete ./ {{repo_dir}}/docker/images/bundle-{{item}}/"
loop:
- frontend
- backend
- exporter
- name: login with docker
when: "push"
community.general.docker_login:
username: "{{docker_id}}"
password: "{{docker_secret}}"
- name: prepare build script
template:
src: build-docker-image.sh
dest: "{{repo_dir}}/docker/images/build.sh"
mode: u=rwx,g=rx,o=rx
- name: obtain version
ansible.builtin.slurp:
src: "{{repo_dir}}/version.txt"
register: "bundle_version"
- name: debug version
debug:
var: bundle_version
- name: set fact
set_fact:
current_version: "{{bundle_version['content'] | b64decode | trim}}"
- name: debug version
debug:
var: current_version
- name: build images
environment:
PENPOT_BUILD_PLATFORM: "{{platform}}"
PENPOT_BUILD_TAGS: "{{current_version}},latest"
PENPOT_BUILD_BRANCH: "{{build_branch}}"
PENPOT_BUILD_PUSH: "{{push|to_json}}"
shell:
chdir: "{{repo_dir}}/docker/images/"
cmd: "./build.sh {{item}}"
loop:
- backend
- frontend
- exporter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment